일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- Helm
- 스프링부트
- Kafka
- 0 replica
- Strimzi
- Salting
- minreplica
- blue-green
- Software maestro
- Leaderboard
- hammerDB
- keda
- zset
- logback
- eks
- docket
- Debezium
- Grafana
- yml
- propogation
- Database
- SW Maestro
- 동등성
- MSSQL
- spring boot
- SW 마에스트로
- Benchmarks
- traceId
- slow query
- Kubernetes
- Today
- Total
김태오
Prometheus & Grafana 설정 본문
프로젝트의 monitoring을 위하여 prometheus와 grafana를 도입하였다.
많은 경우 함께 쓰이는 오픈소스 도구로 각기 다른 역할을 수행하며, prometheus보다 많은 역할을 수행하는 thanos라는 옵션도 있다.
우선 prometheus server는 metrics를 pull하여 수집하며, metric name 과 dimension에는 key-value data model을 사용한다. pull model은 실시간으로 application endpoints에서 metric을 수집한다. endpoint들을 직접 명시할 필요 없이, spring boot application에 간단한 설정을 하면 swagger과 비슷하게 자동으로 수집이 된다. HTTP 외에도 CPU, memory, disk space 등을 쿼리하여 metric 수집이 가능하다. 다음은 간단한 configuration이다.
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
build.gradle에 추가해준다.
management.endpoints.web.exposure.include=prometheus
application.yaml에 추가해준다.
prometheus를 설치한 후, prometheus.yaml 파일을 설정한다.
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'spring-actuator'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
targets에는 현재 application이 실행될 host와 port가 명시되며, 이곳에서 metric이 수집된다.
./prometheus --config.file=prometheus.yml
config file로 간단히 실행한다.
잘 완요하였다면 port 9090(prometheus default port)를 access할 수 있는데, config file 과 spring boot 에서의 설정이 잘 되었다면 status->targets에서 확인할 수 있다.
Prometheus는 metric 수집만 할 뿐, 직접 metric을 시각화하여 보는 데 불편함이 있다. 다만 Expressions에 query하여 metric을 볼 수는 있다. 이는 PromQL이라는 query 언어로 작동한다.
이런 식으로 http_server_requests_seconds_count라는 쿼리를 날리면 시각화된 그래프가 간소하게 나타나는 것을 볼 수 있다.
이렇듯 prometheus에서 visualization이 가능하지만, grafana라는 시각화 툴을 따로 쓰는 데에는 많은 이점이 있다.
우선 정교하고 복잡한 시각화가 가능하며, Dashboard를 직접 만들어 여러 개의 environment 와 metric을 볼 수 있다. 또한 prometheus에서는 제공하지 않는 alert 기능이 있으며, metric annotation이 가능한 등 여러 부가 기능이 있다.
Grafana의 설정은 간단하다.
systemctl start grafana-server
grafana 설치 후 그냥 실행만 시켜주면 된다.
default port인 3000에서 실행되게 되는데, 첫 로그인 시 기본 credentials 는 admin/admin 이다.
Configurations -> Data Sources로 가 prometheus를 선택한 후 HTTP URL(이전 설정대로라면 http://localhost:9090)을 설정하면 prometheus에서 가져온 metric를 열람할 수 있다.
여기서 Dashboard를 생성하여 Add Query 를 하면 여러 metric을 Dashboard에 담을 수 있다.
Prometheus & Grafana에서 제공하는 Query 종류는 한정적인데, Spring Boot 에서 custom query를 작성하여 본인이 원하는 metrics가 있다면 쉽게 나타낼 수 있다.
local테스트 이후 EC2 production 환경에서 설정은 과정이 동일하며, 3000과 9090 port 만 열어주면 된다.