YUMSERV
article thumbnail
Published 2023. 2. 14. 21:36
[Prometheus] 프로메테우스란 MONITORING
반응형

1. Prometheus 정의

1) Prometheus란

  • 오픈소스 시스템 모니터링
  • Metric을 시계열 데이터(Time-series data : 시간별로 변화하는 데이터)로 수집 저장

2) 특징

  • 다차원 데이터 모델
  • PromQL 쿼리 지원
  • 자체 데이터저장
  • Monitoring-Pull 방식
  • Monitoirng-Push 방식도 지원(Gateway를 이용)

3) 구성방식

4) Metric Type

프로메테우스에서 제공하는 메트릭 타입은 총 4가지가 있습니다.

  • Counter : 모니터링의 누적 개수 혹은 크기. 증가값 
    ex) total_req send/receive bytes, uptime
  • Gauge : 현재 상태 표현. Up&Down 증감값
    ex) cpu/memory usage, tempature, concurrent req
  • Histogram : 특정 기간동안 측정된 값.
  • Summary : Histogram 과 비슷하지만, 분위수(quantiles)를 지원하는점이 다르다.

5) 메트릭 구성

메트릭 값은 위의 사진과 같이 수집이 됩니다.

메트릭명{필드1=값, 필드2=값} 샘플링데이터

 

 

2. 프로메테우스 설치


[설치 환경]
OS : Rocky 9

Docker 환경에서 설치 (기본적인 Docker, Docker-compose 설치 되어있음)

 

1) prometheus docker-compose

$ vi docker-compose.yaml
version: '3.8'
services:
  prometheus:
    container_name: prometheus
    image: prom/prometheus:latest
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention=1h'
      - '--storage.tsdb.retention.size=1TB'
      - '--storage.tsdb.wal-compression'
      - '--web.enable-lifecycle'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--web.listen-address=0.0.0.0:9090'
    volumes:
      - ./config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
    restart: always
    network_mode: "host"
    
 $ docker-compose up -d

 

command 관련 내용
--config.file=/etc/prometheus/prometheus.yml : 설정파일 경로
--storage.tsdb.path=/prometheus : 매트릭 저장소 경로
--storage.tsdb.retention.time=1h : 파티션 관리(오래된 데이터 제거 기간 - default값은 15d)
--storage.tsdb.retension.size=1TB : 파티션 관리(보존할 수 있는 데이터 크기 제한. 용량 초과될 경우 이전 데이터 자동 삭제 - default값은 0(비활성화))
--storage.tsdb.wal-compression : wal 로그 압축. prometheus 2.11.0 이후 default 값으로 활성화 되어있음
--web.enable-lifecycle : http 통신을 통한 prometheus reload 및 shutdown 활성화 옵션
--web.console.libraries=/etc/prometheus/console_libraries : 프로메테우스 웹 콘솔 라이브러리
--web.console.templates=/etc/prometheus/consoles : 프로메테우스 웹 콘솔
--web.listen-address=0.0.0.0:9090 : web 접속 주소 및 포트

 

2) prometheus.yml 파일

기본적인 prometheus 파일 형식

$ vi prometheus.yml
# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

 

 

prometheus.yml 파일 내용 설명
global.scrape_interval : 프로메테우스 데이터 수집 주기 설정
global.evaluation_interval : 메트릭을 평가하는 주기. 그 결과를 바탕으로 알림 발송 할지 결정
alerting : 알림설정 (alert manager)
rule_files : 룰 파일 지정
scrape_configs : 데이터 수집 대상 정의
scape_configs.job : job 은 데이터 수집 하기 위해 설정된 대상 그룹을 정의

 

 

3) web UI 로 확인

기본 포트인 9090 포트로 확인합니다!

http://prometheusIP:9090

prometheus 초기화면

 

 

 

참고 URL 리스트

 

 

반응형

'MONITORING' 카테고리의 다른 글

[Grafana] Grafana 란  (0) 2023.06.28
[Redash] Redash 설치 - Docker  (0) 2023.05.23
[Uptime Kuma] 알림 설정  (0) 2022.08.22
[Uptime Kuma] 설치 및 사용  (0) 2022.08.19
[Zabbix] pdf-report  (0) 2021.03.28
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!