Skip to content

Prometheus

The Prometheus monitoring system and time series database.

Categories

Features

Prometheus's main features are:

  • a multi-dimensional data model with time series data identified by metric name and key/value pairs
  • PromQL, a flexible query language to leverage this dimensionality
  • no reliance on distributed storage; single server nodes are autonomous
  • time series collection happens via a pull model over HTTP
  • pushing time series is supported via an intermediary gateway
  • targets are discovered via service discovery or static configuration
  • multiple modes of graphing and dashboarding support

Components

The Prometheus ecosystem consists of multiple components, many of which are optional:

  • the main Prometheus server which scrapes and stores time series data
  • client libraries for instrumenting application code
  • a push gateway for supporting short-lived jobs
  • special-purpose exporters for services like HAProxy, StatsD, Graphite, etc.
  • an alertmanager to handle alerts
  • various support tools

Most Prometheus components are written in Go, making them easy to build and deploy as static binaries.

Architecture

This diagram illustrates the architecture of Prometheus and some of its ecosystem components:

Prometheus-architecture.svg.png

Prometheus vs InfluxDB

InfluxDB의 데이터 모델

InfluxDB는 시리즈(Series)와 측정(Measurement)이라는 개념을 사용해요. 이게 뭔 소리냐고요? 쉽게 설명해드릴게요!

  • 측정(Measurement): 이건 우리가 측정하고 싶은 대상이에요. 예를 들면 "CPU 사용률", "메모리 사용량" 같은 거죠.
  • 태그(Tag): 데이터를 구분하는 메타데이터예요. "서버 이름", "지역" 같은 정보가 여기에 해당해요.
  • 필드(Field): 실제 측정된 값이에요. "CPU 사용률 80%", "메모리 사용량 4GB" 같은 구체적인 수치가 여기에 들어가요.
  • 타임스탬프(Timestamp): 데이터가 언제 기록되었는지를 나타내요.

이 구조를 사용하면 데이터를 정말 효율적으로 저장하고 검색할 수 있어요. 예를 들어, "서울에 있는 모든 서버의 지난 1시간 동안의 CPU 사용률"을 쉽게 조회할 수 있답니다.

Prometheus의 데이터 모델

Prometheus는 좀 다른 접근 방식을 사용해요. 여기서는 메트릭(Metric)과 레이블(Label)이라는 개념을 사용하죠.

  • 메트릭(Metric): 측정하고자 하는 대상이에요. InfluxDB의 측정(Measurement)과 비슷한 개념이죠.
  • 레이블(Label): 키-값 쌍으로 이루어진 메타데이터예요. InfluxDB의 태그와 비슷하지만, 더 유연하게 사용할 수 있어요.
  • 샘플(Sample): 실제 측정된 값과 타임스탬프의 조합이에요.

Prometheus의 이런 구조는 특히 다차원 데이터를 다루는 데 강점이 있어요. 예를 들어, "HTTP 요청 수"라는 메트릭에 "method", "status_code", "endpoint" 등의 레이블을 붙여서 정말 세밀하게 데이터를 분석할 수 있답니다.

결론은?

데이터 모델의 차이는 각 데이터베이스의 성능과 사용 방식에 큰 영향을 미쳐요.

  • InfluxDB는 시계열 데이터를 정말 빠르게 저장하고 검색하는 데 최적화되어 있죠.
  • 반면 Prometheus는 다차원 데이터를 다루는 데 더 유연해요.

이런 특성 때문에:

  • InfluxDB는 IoT나 센서 데이터 처리에 자주 사용되고,
  • Prometheus는 마이크로서비스 모니터링 같은 복잡한 시스템 관리에 많이 쓰인답니다.

Prometheus vs Grafana

Prometheus와 Grafana는 모니터링 및 시각화를 위한 도구로 자주 함께 사용되지만, 서로 다른 목적을 가지고 설계된 도구입니다. 아래에 주요 차이점을 정리하였습니다.

기능/특징

Prometheus

Grafana

주요 역할

시계열 데이터베이스 및 모니터링 솔루션

데이터 시각화 및 대시보드 관리

기능

  • 메트릭 수집 및 저장
  • 경고(Alert) 생성
  • 쿼리 언어(PromQL)를 통한 데이터 분석
  • 다양한 데이터 소스 시각화
  • 대시보드 구성
  • 알람(Alert) 트리거 관리

데이터 저장

자체 시계열 데이터베이스(TSDB)에 데이터를 저장

데이터를 직접 저장하지 않음. 대신 Prometheus, Elasticsearch, MySQL 등 다양한 소스와 연결

데이터 소스

주로 애플리케이션에서 메트릭을 Pull 방식으로 수집

Prometheus, InfluxDB, Elasticsearch, MySQL 등 여러 소스를 지원

쿼리 언어

PromQL (Prometheus Query Language)

다양한 데이터 소스에 맞는 쿼리 언어 지원

경고 시스템

내장된 Alertmanager를 통해 경고 관리

자체 경고 시스템도 있지만 주로 Prometheus와 같은 도구에서 제공하는 경고를 활용

확장성

단일 노드로 실행 가능, Pushgateway 등을 통해 확장성 보완

다양한 플러그인과 데이터 소스 추가 가능

설치 및 구성

비교적 간단하지만 메트릭 수집을 위한 Exporter가 필요

사용이 쉽고 인터페이스가 직관적

사용 사례

  • 시스템 및 애플리케이션 성능 모니터링
  • 메트릭 기반 분석
  • 데이터 시각화와 대시보드 관리
  • 팀 협업용 도구로 적합

통합 사용

Grafana의 데이터 소스로 주로 사용

Prometheus에서 수집한 데이터를 대시보드로 시각화하는 데 자주 사용

간단한 요약
Prometheus는 데이터를 수집하고 저장하며, 이를 바탕으로 경고를 생성하거나 분석합니다.
Grafana는 Prometheus와 같은 여러 데이터 소스에서 데이터를 가져와 시각화하고 대시보드를 구성합니다.
함께 사용하는 이유
Prometheus는 데이터를 수집하고 저장하는 데 탁월하지만, 시각화 도구로는 적합하지 않습니다. Grafana는 이를 보완해 데이터를 직관적으로 표현할 수 있게 해주므로 두 도구는 서로를 보완하는 관계입니다.
실사용 예시
Prometheus가 CPU 사용량, 메모리 사용량 등의 메트릭을 수집.
Grafana가 Prometheus에서 수집된 데이터를 시각화하여 대시보드에 표시.
시스템 이상 발생 시 Prometheus Alertmanager가 경고를 트리거.

Demo 방법

pushgateway 실행:

docker run --rm -it -p 9091:9091 prom/pushgateway

우선 prometheus.yml 파일을 작성하자:

global:
  scrape_interval: 1s

scrape_configs:
  - job_name: 'pushgateway'
    static_configs:
      - targets: ['192.168.100.153:9091']

  - job_name: 'node'
    static_configs:
      - targets: ['192.168.100.153:9100']

  - job_name: 'gpu'
    static_configs:
      - targets: ['192.168.100.161:9454']

node-exporter 실행:

docker run --rm -it --net="host" --pid="host" -v "/:/host:ro,rslave" quay.io/prometheus/node-exporter:latest --path.rootfs=/host

GPU 검사 필요하면 nvidia-smi-exporter 같은 거 실행하자.

Prometheus 실행:

docker run -it --rm -v ./prometheus.yml:/etc/prometheus/prometheus.yml -p 9090:9090 prom/prometheus

웹브라우저에서 http://localhost:9090/ 으로 접속하면 된다.

pushgateway 으로 샘플 데이터 쏘고 싶다면:

echo "new_metric 100" | curl --data-binary @- http://localhost:9091/metrics/job/pushgateway

Troubleshooting

context deadline exceeded

Error scraping target: Get "http://192.168.1.88:8000/metrics": context deadline exceeded`

Prometheus가 타겟에서 메트릭을 스크랩하는 과정에서 정해진 시간(scrape_timeout) 내에 완료하지 못했음을 의미합니다. 이 문제는 타겟이 응답하는 데 시간이 오래 걸리거나, 네트워크 문제, 방화벽, 또는 Prometheus 설정의 스크랩 시간(scrape_timeout)이 너무 짧기 때문에 발생할 수 있습니다

scrape_configs:
  - job_name: 'prometheus'

    scrape_interval: 5m
    scrape_timeout: 1m

주의할 점은 scrape_intervalscrape_timeout 보다 작으면 안된다.

See also

Favorite site

with Grafana