Apache Prometheus

김도비·2022년 9월 18일
1

Monitoring

목록 보기
3/4

Apache Prometheus

자사 실시간 솔루션 개발 이전에 데이터베이스 및 카프카 관련 메트릭 정보 수집에 관한 요건이 생겨 직접 설치 및 스터디한 결과를 옮겨본다.

프로메테우스는 메트릭 기반의 오픈소스 모니터링 시스템

  • 기능 및 구성
    메트릭 이름 및 / 쌍으로 식별되는 시계열 데이터가 있는 다차원
    이러한 차원을 활용하는 유연한 쿼리 언어인 PromQL. 이를 통해 성능 분석이 가능
    다양한 그래프 및 지원(예. 그라파나)
    Alertmanager를 통한 알림 생성 발생

  • Prometheus 특징
    HTTP) Pull 기반으로 모든 데이터를 가져옴
    다차원 데이터 모델 가능
    분산 스토리지에 대해서 어떠한 의존성도 X

  • Architecture
    Service Discovery : 을 발견. 프로메테우스는 기본적으로 모니터링 대상 목록을 유지.
    Pushgateway : Pushgateway는 쉽게말해 Proxy Forwarding을 해서 접근할 수 없는 곳에 데이터가 존재하는 경우에 사용
    용할 수 있는 대안. Application 이 pushgateway 에 메트릭을 push한 후, prometheus server 가 pushgateway 에 접근
    해 metric 을 pull 해서 오는 방식으로 동작
    Jobs/Exporter : Exporter는 프로메테우스에게 메트릭을 가져가도록 특정 서비스에 metric을 노출하게 하는 Agent.
    Exporter 는 서버 상태를 나타내는 Node exporter , SQL Exporter 등 다양한 커스텀 exporter 이 개발되어 사용되고 있음
    DashBoard: 내장되어있는 프로메테우스 Web UI 보단 Grafana 를 사용
    Alert manager : PromQL로 실행된 모든 결과는 알림이고, 이 알림 중에서 특정 알림에 대해 규칙을 만들어서 이메일, 페이저듀티, 기타 애플리케이션으로 전송

  • Prometheus 장/단점
    장점
    Pull 의 구조를 채택함으로써, 모든 메트릭의 정보를 중앙 서버로 보내지 않아도 됨. 서버 부하에 대해 컨트롤 가능
    Kubernetes 환경에서 하고, Grafana와의 연동을 통한
    데이터 유지와 확인데이터 저장소가 저장소로 구성되어있어, 양의 정보를 검색 가능
    단점
    싱글 호스트 아키텍처이기 때문에 저장용량이 부족하면 밖에 방법이 없음
    프로메테우스 서버가 다운되거나, 설정 변경 등을 위해서 재시작을 할 경우 그간의 metric은 됨. 장기간 데이터 보관 및 고가용성 문제
    단점을 보완하기 위해서 타노스라는 시스템이 등장.
    참조 : https://bcho.tistory.com/1375

프로메테우스 익스포터를 통해 메트릭 수집을 진행함

#1. MYSQL Exporter Installation

# wget 명령어를 통한 설치
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
# 설치파일 압축 해제
Tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz

#2. Mysql Exporter 환경설정(mysqld_exporter.cnf)

### #2. Mysql User/Password
user=prometheus
password=prometheus

#3. Mysql Exporter 구동

# Mysql Exporter Pull Metric
./mysqld_exporter --config.my-cnf ./mysqld_exporter.cnf --collect.global_status --collect.info_schema.innodb_metrics --collect.
auto_increment.columns --collect.info_schema.processlist --collect.binlog_size --collect.info_schema.tablestats --collect.global_variables
--collect.info_schema.query_response_time --collect.info_schema.userstats --collect.info_schema.tables --collect.perf_schema.tablelocks
--collect.perf_schema.file_events --collect.perf_schema.eventswaits --collect.perf_schema.indexiowaits --collect.perf_schema.tableiowaits
--collect.slave_status --web.listen-address=192.168.0.101:9104

위에 Mysql Exporter 수집 메트릭 정리 참조 : https://github.com/prometheus/mysqld_exporter

#4. Kafka Exporter Installation

 wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gz

Tar zxf kafka_exporter-1.2.0.linux-amd64.tar.gz

#5. Kafka Exporter 구동

# Mysql Exporter Pull Metric
./kafka_exporter --kafka.server=rwkcdh01:9092 --kafka.server=rwkcdh01:9092 --kafka.server=rwkcdh03:9092 --web.listen-address=:9309

#6. Prometheus Installation

# wget 명령어를 통한 설치
wget https://github.com/prometheus/prometheus/releases/download/v2.24.1/prometheus-2.24.1.linux-amd64.tar.gz
# 설치파일 압축 해제
Tar zxf prometheus-2.24.1.linux-amd64.tar.gz

#7. Prometheus 환경설정(prometheus.yml)

# my global config
global:
 scrape_interval: 15s # 메트릭 호출 설정. 디폴트 1분
 evaluation_interval: 15s # 규칙 호출 설정. 디폴트 1분
 # 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:
# 수집할 메트릭 설정
scrape_configs:
 # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
 - job_name: 'servermetrics'
 # metrics_path defaults to '/metrics'
 # scheme defaults to 'http'.
 static_configs:
 - targets: ['113.198.103.141:9100','192.168.0.101:9100']
 - job_name: 'mariadb'
 static_configs:
 - targets: ['113.198.103.137:9104']
 - job_name: 'kafka'
 static_configs:
 - targets: ['113.139.103.137:9309']

#8. Prometheus 구동

# 구동
./prometheus --web.listen-address=:19090 --config.file=./prometheus.yml 
profile
모든 걸 기록하자

0개의 댓글