Prometheus

Prometheus

CNCF ํ”„๋กœ์ ํŠธ ์ค‘ ํ•˜๋‚˜๋กœ ์‹œ์Šคํ…œ๊ณผ ์„œ๋น„์Šค๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๋Š” ๋„๊ตฌ์ด๋‹ค.

Kubernetes ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌ์˜ ๊ฑฐ์˜ ํ‘œ์ค€์ด๋‹ค.

Prometheus architecture

Prometheus๋Š” Service Discovery, Jobs/Exporters, Pushgateway, Prometheus Server, Alertmanageer ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

๊ฐ Prometheus ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž.

Service discovery

Prometheus๋Š” *Service Discovery์™€ ์—ฐ๋™ํ•˜์—ฌ Pod๊ฐ€ ์‚ญ์ œ๋˜๊ฑฐ๋‚˜ ์ถ”๊ฐ€๋˜๋Š” ๋“ฑ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ๋ฐœ์ƒํ•˜๋ฉด ์ž๋™์œผ๋กœ ํƒ์ง€ํ•˜์—ฌ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•œ๋‹ค.

  • ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค Service Discovery๋Š” CoreDNS์— ์„œ๋น„์Šค Domain Name์„ ๋“ฑ๋กํ•˜๊ณ , ๋™๋กํ•œ ์„œ๋น„์Šค ๋ชฉ๋ก๊ณผ IP, ํฌํŠธ๋ฅผ ์ฐพ์•„์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

Jobs/exporters

Jobs/exporters๋Š” ์‹ค์ œ๋กœ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์ด๋‹ค.

๋ฉ”ํŠธ๋ฆญ ์ˆ˜์ง‘ ๊ณผ์ •์€ exporter๊ฐ€ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•˜๊ณ  /metrics ๋ผ๋Š” HTTP endpoint๋ฅผ ์ œ๊ณตํ•œ๋‹ค. Prometheus Server๋Š” exporter์—์„œ ์ œ๊ณตํ•˜๋Š” ์—”๋“œํฌ์ธํŠธ๋กœ ์ ‘์†ํ•˜์—ฌ Pulling ๋ฐฉ์‹์œผ๋กœ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ , ์‹œ๊ฐํ™” ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜์ง‘ํ•œ ๋ฉ”ํŠธ๋ฆญ์„ ์กฐํšŒํ•˜๊ณ  ํ…Œ์ด๋ธ”์ด๋‚˜ ๊ทธ๋ž˜ํ”„ ํ˜•ํƒœ๋กœ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.

Pushgateway

Pushgateway๋Š” Push ๋ฐฉ์‹์œผ๋กœ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•œ๋‹ค.

์ˆ˜์ง‘ ์—์ด์ „ํŠธ๊ฐ€ ๋ฉ”ํŠธ๋ฆญ์„ Pushgateway์— Pushํ•˜๋ฉด, Prometheus๊ฐ€ Pushgateway์—์„œ ๋ฉ”ํŠธ๋ฆญ์„ Pulling ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.

Prometheus server

Prometheus server๋Š” Retrieval, TSDB, HTTP server ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

Retrieval์€ Service discovery์—์„œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋Œ€์ƒ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์™€์„œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋Œ€์ƒ์œผ๋กœ ๋ถ€ํ„ฐ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•˜๊ณ  TSDB (์‹œ๊ณ„์—ด DB)์— ์ €์žฅํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. TSDB์— ์ €์žฅํ•œ ๋ฉ”ํŠธ๋ฆญ์€ HTTP server๋ฅผ ํ†ตํ•ด PromQL๋กœ ๋ฉ”ํŠธ๋ฆญ์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

Alertmanager

Prometheus server๋กœ ๋ถ€ํ„ฐ Alert๋ฅผ ์ „๋‹ฌ ๋ฐ›์•„ ์ ์ ˆํ•œ ํ˜•์‹์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ , ๋ณ€๊ฒฝํ•œ Alert๋ฅผ ์ด๋ฉ”์ผ ๋“ฑ์œผ๋กœ ์ „์†กํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

Prometheus Data & Model

Data Model

Prometheus ๋ฉ”ํŠธ๋ฆญ์€ ๋ผ๋ฒจ๊ณผ ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ ๋ฉ”ํŠธ๋ฆญ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

๋‹ค์Œ์€ ๋ฉ”ํŠธ๋ฆญ์˜ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ ํฌ๋งท์ด๋‹ค.

<metric_name>{<label name>={label value}, ...}

๋‹ค์Œ์€ http_requests_total ๋ฉ”ํŠธ๋ฆญ์˜ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ ์ •์˜ ์˜ˆ์‹œ์ด๋‹ค.

Simple Modelhttp_requests_total 5m

Model with label

http_requests_total {method="GET"} 5m

Model with label and filter

http_requests_total {job=~".*", method="GET"} 5m

Metric Typpes

Promethues๋Š” 4๊ฐ€์ง€ ๋ฉ”ํŠธ๋ฆญ ํƒ€์ž…(Counter, Gauage, Histogram, Summary)์„ ์ •์˜ํ•˜์—ฌ ์ €์žฅํ•œ๋‹ค.

CounterGaugeHistogramSummary

๋ˆ„์ ๊ฐœ์ˆ˜, ํฌ๊ธฐ

ํ˜„์žฌ ๊ฐ’, ์ฆ๊ฐ€/๊ฐ์†Œ ๊ฐ’

ํŠน์ • ๊ธฐ๊ฐ„ ์ง‘๊ณ„(๋ฒ„ํ‚ท๋ณ„)

ํŠน์ • ๊ธฐ๊ฐ„ ์ง‘๊ณ„(๋ฒ„ํ‚ท๋ณ„ X)

request count, error count

memory usage, queue size

response size

response time

Prometheus Configuration

Prometheus server ์„ค์ •์€ prometheus.yaml ํŒŒ์ผ๋กœ ์ •์˜ํ•œ๋‹ค.

๋ฉ”ํŠธ๋ฆญ ์ˆ˜์ง‘ ๊ฐ„๊ฒฉ, Alert ์„ค์ •, ๋ฉ”ํŠธ๋ฆญ ์ง‘๊ณ„ ๊ทœ์น™, ์–ด๋–ค exporter๋กœ ๋ถ€ํ„ฐ ๋ฉ”ํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ• ์ง€ ๋“ฑ์„ ์ •์˜ํ•œ๋‹ค.

# ๊ธฐ๋ณธ์ ์ธ ์ „์—ญ ์„ค์ •
global:
  scrape_interval:     15s # 15์ดˆ๋งˆ๋‹ค ๋งคํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•œ๋‹ค.
  evaluation_interval: 15s # 15์ดˆ๋งˆ๋‹ค ๊ทœ์น™์„ ํ‰๊ฐ€ํ•œ๋‹ค.
  
# Alertmanager ์„ค์ •
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
  
# ๊ทœ์น™์„ ์ฒ˜์Œ ํ•œ๋ฒˆ ๋กœ๋”ฉํ•˜๊ณ  'evaluation_interval'์„ค์ •์— ๋”ฐ๋ผ ์ •๊ธฐ์ ์œผ๋กœ ๊ทœ์น™์„ ํ‰๊ฐ€ํ•œ๋‹ค.
rule_files:
  - "example_rules.yml"
  # - "test_rules.yml"
  
# ๋งคํŠธ๋ฆญ์„ ์ˆ˜์ง‘ํ•  ์—”๋“œํฌ์ธํŠธ๋ฅผ ์„ค์ •. ์—ฌ๊ธฐ์„œ๋Š” Prometheus ์„œ๋ฒ„ ์ž์‹ ์„ ์„ค์ •ํ–ˆ๋‹ค.
scrape_configs:
  # ์ด ์„ค์ •์—์„œ ์ˆ˜์ง‘ํ•œ ํƒ€์ž„์‹œ๋ฆฌ์ฆˆ์— 'job=<job_name>'์œผ๋กœ ์žก์˜ ์ด๋ฆ„์„ ์„ค์ •ํ•œ๋‹ค.
  - job_name: 'prometheus'    # 'metrics_path'๋ผ๋Š” ์„ค์ •์˜ ๊ธฐ๋ณธ ๊ฐ’์€ '/metrics'์ด๊ณ  ํ”„๋กœํ† ์ฝœ ๊ธฐ๋ณธ๊ฐ’์€ 'http'์ด๋‹ค.
    static_configs:
    - targets: ['localhost:9090']

PromQL

PromQL์€ Prometheus Query Language ์ด๋‹ค. PromQL์„ ์ด์šฉํ•˜์—ฌ Prometheus server ์—์„œ ๋ฉ”ํŠธ๋ฆญ์„ ํ•„ํ„ฐ๋ง, ์ถ”์ถœ, ์กฐํšŒ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค.

String, Scalar, Instant Vector, Range Vector๋กœ ๋ฉ”ํŠธ๋ฆญ์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ

Last updated