Prometheus hello world 프로젝트
정상 설치 및 실행하기 위해 사용자 환경에 따라 기본적으로 변경되어야 하는 설정은 다음과 같다.
- Prometheus:
- ./prometheus/prometheus.yml
- alerting.alertmanagers.static_configs.targets: alertmanager endpoint 설정 필요
- ./prometheus/sd_configs/file/*.yml
- scrape target 추가를 위한 endpoint(IP 및 PORT 정보) 설정 필요
- ./prometheus/prometheus.yml
- Grafana:
- ./grafana/cert/*
- HTTPS 인증서 및 키 파일 추가 필요
- ./grafana/grafana.ini
- server.domain: 도메인 설정 필요
- server.cert_file, server.cert_key: 인증서 관련 파일 경로 설정 필요
- security.admin_password: Grafana 관리자 계정 비밀번호 설정 필요
- ./grafana/provisioning/datasources/datasources.yml
- datasources.url: Prometheus endpoint 설정 필요
- ./grafana/cert/*
- Alertmanager:
- ./alertmanager/alertmanager.yml
- global.slack_api_url: slack webhook URL 설정 필요
- ./alertmanager/alertmanager.yml
추가적으로 SpringBoot metrics 수집을 위한 maven pom.xml, application.yml 및 JMX exporter metrics 수집을 위한 설정은 아래와 같다.
- SpringBoot
- pom.xml
<dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.8.2</version> </dependency>
- application.yml
management: endpoint: enables: true metrics: tags: application: springboot endpoints: web: exposure: include: "*"
- pom.xml
- JMX-exporter
- JVM 실행 옵션
# non-tomcat JVM application(>= java 7)의 경우 -javaagent:${라이브러리_디렉토리_경로}/jmx_prometheus_javaagent-0.16.1.jar=${포트}:${설정파일_디렉토리_경로}/jmx_exporter_config.yml # tomcat(>= java 7) JVM의 경우 CATALINA_OPTS="${CATALINA_OPTS} -javaagent:${라이브러리_디렉토리_경로}/jmx_prometheus_javaagent-0.16.1.jar=${포트}:${설정파일_디렉토리_경로}/jmx_exporter_config.yml"
- JVM 실행 옵션
Docker를 이용해 설치 및 실행하며 여러 docker image를 사용하기 때문에 docker-compose를 이용해 container를 관리한다.
해당 프로젝트는 아래 환경에서 정상 동작했음을 테스트했다.
- OS: CentOS Linux release 7.8.2003 (Core)
- Kernel version: 3.10.0-1127.18.2.el7.x86_64 #1 SMP Sun Jul 26 15:27:06 UTC 2020
- Docker version: 20.10.5
- Docker-compose version: 1.28.6, build 5db8d86f
- Prometheus: v2.32.0
- Cadvisor: v0.37.5
- Node-exporter: v1.3.1
- JMX-exporter: 0.16.1
- Grafana: 8.3.3
- SpringBoot (maven dependency):
- spring-boot-starter-parent: 2.3.1.RELEASE
- micrometer-registry-prometheus: 1.8.2
- Alertmanager: v0.22.2
- project clone하기
git clone https://github.com/pyo-counting/hello-world-prometheus.git
- 프로젝트 디렉토리로 이동
cd hello-world-prometheus
- docker-compose 실행 및 확인
docker-compsoe up -d docker-compsoe ps
- docker-compose down
docker-compsoe down -v
- Architecture overview은 draw.io를 통해 작성
- Prometheus에 대한 고가용성(High Availability)을 위해 Cortex를 이용할 수 있으며 관련해서는 hello-world-cortex 프로젝트 참고