spring boot + prometheus + grafana
의존성 추가
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
runtimeOnly("io.micrometer:micrometer-registry-prometheus")
...생략...
}
spring boot 실행
application.yml 설정
spring:
application:
name: monitoring
management:
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: health, info, metrics, prometheus
metrics:
tags:
application: ${spring.application.name}
/actuator/prometheus api 확인
prometheus 실행
prometheus.yml 작성
global:
scrape_interval: 10s
evaluation_interval: 1m
external_labels:
monitor: 'study-server'
scrape_configs:
- job_name: 'spring-actuator'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
docker 실행
docker run -d -p 9090:9090 -v {파일경로}/prometheus.yml:/etc/prometheus/prometheus.yml --network="host" --name prometheus prom/prometheus
prometheus 접속
grafana 연동
docker 실행
docker run -d -p 3000:3000 --network="host" --name grafana grafana/grafana
grafna 접속