Skip to content

๐Ÿ–ฅ๏ธ ๋กœ๊น…&๋ชจ๋‹ˆํ„ฐ๋ง

Redddy edited this page Aug 9, 2024 · 19 revisions

๋„์‹ํ™”

image

๋กœ๊น… ๋ ˆ๋ฒจ

  • ์ปค์Šคํ…€ ์˜ˆ์™ธ: warn
  • Exception: error
  • ํ˜„์žฌ ์ถ”๊ฐ€๋กœ info ๋กœ ๋‚จ๊ธฐ๋Š” ์ •๋ณด๋Š” ์—†์Šต๋‹ˆ๋‹ค.

1. ๋กœ๊น…

Logback

๋กœ๊น… ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

  • ๋ฉ”ํŠธ๋ฆญ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋””๋ฒ„๊น… ์šฉ๋„์˜ ๋กœ๊ทธ๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.
  • ์ž๋ฐ” ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค.

2. ์ˆ˜์ง‘

Grafana Loki

๋กœ๊ทธ ์ง‘๊ณ„ ์‹œ์Šคํ…œ

  • ๋ฉ”ํƒ€ ์ •๋ณด๋งŒ ์ธ๋ฑ์‹ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ๋กœ๊ทธ ์ง‘๊ณ„ ํˆด์— ๋น„ํ•ด ๋ฆฌ์†Œ์Šค์™€ ๊ด€๋ฆฌ ๋น„์šฉ์ด ์ ๋‹ค.
  • Grafana์—์„œ ์ œ๊ณตํ•˜๋Š” ๋กœ๊ทธ ์ง‘๊ณ„ ํˆด์ด๊ธฐ ๋•Œ๋ฌธ์— Grafana์™€ ํ†ตํ•ฉํ•˜๊ธฐ ํŽธ๋ฆฌํ•˜๋‹ค.

Promtail

๋กœ๊ทธ ์ปจํ…์ธ ๋ฅผ Grafana Loki์—๊ฒŒ ์ „์†กํ•˜๋Š” ์—์ด์ „ํŠธ

  • Grafana Loki๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋กœ๊ทธ ์ˆ˜์ง‘ ์—์ด์ „ํŠธ๋กœ ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ๋กœ์ปฌ ๋กœ๊ทธ๋ฅผ loki์—๊ฒŒ pushํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

Prometheus

๋ฉ”ํŠธ๋ฆญ ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ๋ฐ ์ €์žฅ

  • ๋””๋ฒ„๊น… ์šฉ๋„์˜ ๋กœ๊น… ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ฉ”ํŠธ๋ฆญ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ  ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

3. ๋ชจ๋‹ˆํ„ฐ๋ง

Grafana

๋กœ๊ทธ & ๋ฉ”ํŠธ๋ฆญ ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

  • ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ์ง€์›ํ•˜๊ณ , ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

์ธํ”„๋ผ ๊ฒฝ๋กœ

docker/compose

  • be_app-docker.compose.yml
  • be_monitoring-docker-compose.yml
  • nginx-docker-compose.yml

๋กœ๊น… ๊ตฌ์ถ• ๊ณผ์ •

be_app-docker-compose.yml ์— ๋กœ๊น… volumes(์ปจํ…Œ์ด๋„ˆ์™€ ํ˜ธ์ŠคํŠธ ์‹œ์Šคํ…œ ๊ฐ„์— ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ  & ๋ฐ์ดํ„ฐ ์˜๊ตฌ ์ €์žฅ ๊ฐ€๋Šฅ) ์ถ”๊ฐ€

  springboot:
    container_name: coduo_springboot-app
    ...
    volumes:
      # ๋กœ๊ทธ ํŒŒ์ผ์„ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ /logs ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋งˆ์šดํŠธ
      - ${SERVER_LOGS_PATH}/springboot-app:/logs
      # ๋ฐฑ์—… ๋กœ๊ทธ ํŒŒ์ผ์„ /logs/backup ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋งˆ์šดํŠธ
      - ${SERVER_LOGS_PATH}/springboot-app/backup:/logs/backup

/logs/springboot-app ๊ฒฝ๋กœ์— ๋“ค์–ด๊ฐ€๋ฉด,

  • backup
  • debug
  • error
  • info
  • warn

ํด๋”๊ฐ€ ์กด์žฌํ•œ๋‹ค.

๋กœ๊ทธ ๋ ˆ๋ฒจ ๋ณ„๋กœ ๋กœ๊ทธ ํด๋”๋ฅผ ๋ถ„๋ฅ˜ํ•ด ๋‘์—ˆ๋‹ค.
๊ฐ ํด๋”์— ๋“ค์–ด๊ฐ€๋ณด๋ฉด ๋‚ ์งœ ๋ณ„๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ƒ์„ฑ๋œ ๋กœ๊ทธ ํŒŒ์ผ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
image

๋ชจ๋‹ˆํ„ฐ๋ง & ๋Œ€์‹œ๋ณด๋“œ ๊ตฌ์ถ• ๊ณผ์ •

๋กœํ‚ค ์„ค์น˜ ๋ฐ ์„ค์ •

๋กœํ‚ค ๊ตฌ๋™์— ํ•„์š”ํ•œ ์„ค์ • ํŒŒ์ผ์„ loki-config.yml๋กœ ์ •์˜ํ•œ๋‹ค.

auth_enabled: false

server:
  http_listen_port: 3100  # ๋กœํ‚ค port

ingester:
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
  chunk_idle_period: 5m
  chunk_retain_period: 30s
  max_transfer_retries: 0

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 168h

storage_config:
  boltdb_shipper:
    active_index_directory: /loki/index
    cache_location: /loki/cache
    shared_store: filesystem
  filesystem:
    directory: /loki/chunks

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h

chunk_store_config:
  max_look_back_period: 0s

table_manager:
  retention_deletes_enabled: false
  retention_period: 0s

be_monitoring-docker-compose.yml์— loki ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์„ค์น˜ํ•œ๋‹ค.

loki:
    container_name: coduo_loki
    image: grafana/loki
    # 3100 ํฌํŠธ๋กœ loki ์ ‘๊ทผ ๊ฐ€๋Šฅ
    ports:
      - "3100:3100"
    # loki ์„ค์ • ํŒŒ์ผ์„ ${your docker data path}/loki/config/loki-config.yml ๋กœ ๋งˆ์šดํŠธ
    volumes:
      - ${your docker data path}/loki/config/loki-config.yml:/etc/loki/local-config.yml
    networks:
      - coduo_net
    command: -config.file=/etc/loki/local-config.yaml

ํ”„๋กฌํ…Œ์ผ ์„ค์น˜ ๋ฐ ์„ค์ •

ํ”„๋กฌํ…Œ์ผ ๊ตฌ๋™์„ ์œ„ํ•œ ์„ค์ • ํŒŒ์ผ์„ promtail-config.yml๋กœ ์ƒ์„ฑํ•œ๋‹ค.

server:
  http_listen_port: 9080

positions:
  filename: /tmp/positions.yml

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

scrape_configs:
  - job_name: springboot-app_info
    static_configs:
      - targets:
          - localhost
        labels:
          job: info_logs
          __path__: /logs/springboo-app/info/*.log # info ํด๋” ๋‚ด์— log ํŒŒ์ผ๋“ค ๋ชจ๋‘ ์ˆ˜์ง‘

  - job_name: springboot-app_warn
    static_configs:
      - targets:
          - localhost
        labels:
          job: warn_logs
          __path__: /logs/springboot-app/warn/*.log # warn ํด๋” ๋‚ด์— log ํŒŒ์ผ๋“ค ๋ชจ๋‘
 ์ˆ˜์ง‘

  - job_name: springboot-app_error
    static_configs:
      - targets:
          - localhost
        labels:
          job: error_logs
          __path__: /logs/springboot-app/error/*.log # error ํด๋” ๋‚ด์— log ํŒŒ์ผ๋“ค ๋ชจ
๋‘ ์ˆ˜์ง‘

์ด๋•Œ scrape_configs๋ฅผ ์ž˜๋ชป ๊ธฐ์ž…ํ•˜๋ฉด ๋กœ๊ทธ ๋ฐ์ดํ„ฐ๊ฐ€ ์กฐํšŒ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์‹ ๊ฒฝ์จ์„œ ์ž‘์„ฑํ•œ๋‹ค.

์ด์ œ be_monitoring-docker-compose.yml์— promtail์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์„ค์น˜ํ•œ๋‹ค.

promtail:
    container_name: coduo_promtail
    image: grafana/promtail
    # 9080 ํฌํŠธ๋กœ promtail ์ ‘๊ทผ ๊ฐ€๋Šฅ
    ports:
      - "9080:9080"
    volumes:
      # promtail ์„ค์ • ํŒŒ์ผ์„ ${your docker data path}/config/promtail-config.yml ๋กœ ๋งˆ์šดํŠธ
      - ${your docker data path}/promtail/config/promtail-config.yml:/etc/promtail/config.yml
      # ๋กœ๊ทธ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ Promtail์ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งˆ์šดํŠธ
      - ${your log data path}/logs:/logs
      - ${your docker data path}/promtail/tmp:/tmp
    networks:
      - coduo_net
    command: -config.file=/etc/promtail/config.yml
    # loki ์‹คํ–‰ ํ›„ promtail์ด ์‹œ์ž‘๋œ๋‹ค.
    depends_on:
      - loki

ํ”„๋กœ๋ฉ”ํ…Œ์šฐ์Šค ์„ค์น˜ ๋ฐ ์„ค์ •

ํ”„๋กœ๋ฉ”ํ…Œ์šฐ์Šค ๊ตฌ๋™์„ ์œ„ํ•œ ์„ค์ • ํŒŒ์ผ์„ prometheus.yml์— ์ •์˜ํ•œ๋‹ค.

global:
  scrape_interval: 30s

scrape_configs:
  - job_name: 'prometheus'
    metrics_path: '/actuator/prometheus'  # ์Šคํ”„๋ง์— ์ถ”๊ฐ€๋œ acturator ๋ชจ๋‹ˆํ„ฐ๋ง ๊ฒฝ๋กœ
    static_configs:
      - targets: ['172.19.0.8:8080']

docker compose์— ์ถ”๊ฐ€ํ•˜์—ฌ ์„ค์น˜ํ•œ๋‹ค.

prometheus:
    container_name: coduo_prometheus
    image: prom/prometheus
    # 9090 ํฌํŠธ๋กœ prometheus ์ ‘๊ทผ ๊ฐ€๋Šฅ
    ports:
      - "9090:9090"
    # prometheus ์„ค์ • ํŒŒ์ผ์„ ${your docker data path}/prometheus/config/prometheus.yml ๋กœ ๋งˆ์šดํŠธ
    volumes:
      - ${your docker data path}/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml
    networks:
      - coduo_net

๊ทธ๋ผํŒŒ๋‚˜ ์„ค์ •

์ด์ œ ์œ„์—์„œ ์„ค์น˜ํ•œ ๋„๊ตฌ๋“ค์ด ์ˆ˜์ง‘ํ•œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ์ดํ„ฐ๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋Š” ๊ทธ๋ผํŒŒ๋‚˜๋ฅผ ์„ค์น˜ํ•œ๋‹ค. docker-compose์— ์ถ”๊ฐ€ํ•œ๋‹ค.

grafana:
    container_name: coduo_grafana
    image: grafana/grafana:latest
    user: root
    # 3001 ํฌํŠธ๋กœ grafana ์ ‘๊ทผ ๊ฐ€๋Šฅ
    ports:
      - "3001:3001"
    volumes:
      # grafana ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ${your docker data path}/grafana ๋กœ ๋งˆ์šดํŠธ (๋Œ€์‹œ๋ณด๋“œ, ์„ค์ • ๋“ฑ์„ ์ €์žฅ)
      - ${your docker data path}/grafana:/var/lib/grafana
      # grafana ์„ค์ • ํŒŒ์ผ์„ ${your docker data path}/grafana/config/grafana.ini ๋กœ ๋งˆ์šดํŠธ
      - ${your docker data path}/grafana/config/grafana.ini:/etc/grafana/grafana.ini
    environment:
      # grafana ์„œ๋ฒ„์˜ ๋ฃจํŠธ URL ์„ ํ•ด๋‹น ์ฃผ์†Œ๋กœ ์„ค์ •
      - GF_SERVER_ROOT_URL=https://coduo.site/grafana  # root url์„ ์ž„์˜์ ์œผ๋กœ ๋ณ€๊ฒฝ
      - GF_SERVER_SERVE_FROM_SUB_PATH=true
    networks:
      - coduo_net

์ด์ œ ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ชจ๋‹ˆํ„ฐ๋งํˆด์— ์ ‘์†ํ•œ๋‹ค. image

๋ฐ์ดํ„ฐ ์†Œ์Šค์— ์œ„์— ์„ค์น˜ํ•œ ํ”„๋กœ๋ฉ”ํ…Œ์šฐ์Šค, loki๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์ˆ˜์ง‘๋œ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•œ๋‹ค. image

๊ทธ๋ผํŒŒ๋‚˜ ๋งํฌ: https://coduo.site/grafana/

๐Ÿ€ ์ฝ”๋”ฉํ•ด๋“€์˜ค

์ „์ฒด

์ •๋ณด

BE

FE

๊ธฐ์ˆ 

์ปจ๋ฒค์…˜

ํ…Œ์ŠคํŠธ

์„ฑ๋Šฅ ๊ฐœ์„  & ์ ‘๊ทผ์„ฑ ๊ฐœ์„  ๋ฆฌํฌํŠธ

์ธํ”„๋ผ

Clone this wiki locally