Skip to content

Commit

Permalink
Merge pull request #100 from MJU-InsuranceSystem/feature/monitor
Browse files Browse the repository at this point in the history
Feat : log 수집을 위한 promtail, loki 초기 설정
  • Loading branch information
TaetaetaE01 authored Dec 4, 2024
2 parents 1ad3723 + 2f6d15d commit edcf1ce
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 16 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ repositories {

dependencies {

// log
implementation 'org.springframework.boot:spring-boot-starter-logging'

//cloud
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' //AWS S3

Expand Down
53 changes: 37 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ services:
ports:
- "80:8080"
- "9292:9292"
volumes:
- ./logs/all:/app/logs/all # ALL_LOG 파일 경로 마운트
- ./logs/warn:/app/logs/warn # WARN_LOG 파일 경로 마운트
- ./logs/error:/app/logs/error # ERROR_LOG 파일 경로 마운트
networks:
- my_network
environment:
- DEV_ECR_REGISTRY_ALIAS=${DEV_ECR_REGISTRY_ALIAS}


prometheus:
image: prom/prometheus:latest
container_name: prometheus
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
# - ./prometheus/prometheus-volume:/prometheus
ports:
- '9090:9090'
command:
Expand All @@ -28,24 +30,43 @@ services:

grafana:
image: grafana/grafana:latest
container_name: grafana_container
container_name: grafana
ports:
- 3000:3000

promtail:
container_name: promtail
image: grafana/promtail:latest
restart: always
ports:
- '9080:9080'
volumes:
- ./promtail/promtail-config.yml:/etc/promtail/promtail-config.yml
- ./logs/all:/var/logs/all
- ./logs/warn:/var/logs/warn
- ./logs/error:/var/logs/error
command:
-config.file=/etc/promtail/promtail-config.yml
depends_on:
- loki
networks:
- my_network

loki:
image: grafana/loki:latest
container_name: loki
ports:
- "3100:3100"
command:
- '--config.file=/etc/loki/loki-config.yml'
volumes:
- ./loki/loki-config.yml:/etc/loki/loki-config.yml
restart: always
networks:
- my_network

networks:
my_network: # 네트워크 정의
driver: bridge

# airdnb-prometheus:
# image: prom/prometheus
# container_name: prometheus-container
# volumes:
# - ./prometheus.yml:/etc/prometheus/prometheus.yml # Prometheus 설정 파일 경로
# ports:
# - "9090:9090" # Prometheus UI
# depends_on:
# - app # app 서비스가 실행된 후에 시작
# airdnb-local-grafana:
# image: grafana/grafana
# ports:
# - "3000:3000"

Empty file added loki/loki-config.yml
Empty file.
34 changes: 34 additions & 0 deletions promtail/promtail-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /positions.yaml

clients:
- url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: all
static_configs:
- targets:
- localhost
labels:
job: all_logs
__path__: /var/logs/all/*.log

- job_name: warn
static_configs:
- targets:
- localhost
labels:
job: warn_logs
__path__: /var/logs/warn/*.log

- job_name: error
static_configs:
- targets:
- localhost
labels:
job: error_logs
__path__: /var/logs/error/*.log
55 changes: 55 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<configuration>
<!-- 전체 설정의 시작 -->

<!-- INFO 이상 모든 로그를 기록할 Appender -->
<appender name="ALL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/all/logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/all/logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>100MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>

<!-- WARN 레벨 이상의 로그만 기록할 Appender -->
<appender name="WARN_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/warn/logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/warn/logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>100MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
</appender>

<!-- ERROR 레벨 이상의 로그만 기록할 Appender -->
<appender name="ERROR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/error/logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/error/logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>100MB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>

<!-- Root Logger 설정 -->
<root level="INFO">
<appender-ref ref="ALL_LOG"/>
<appender-ref ref="WARN_LOG"/>
<appender-ref ref="ERROR_LOG"/>
</root>
</configuration>

0 comments on commit edcf1ce

Please sign in to comment.