1. 설정하기
build.gradle
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
application.yml
management:
endpoint:
health:
show-components: always
# show-details: always
endpoints:
web:
exposure:
include: "*"
info:
java:
enabled: true
os:
enabled: true
env:
enabled: true
git:
mode: full
server:
port: 8090
compose.yml
services:
prometheus:
container_name: prometheus
image: prom/prometheus:latest
restart: always
ports:
- 9090:9090
command:
- '--web.enable-lifecycle'
- '--config.file=/etc/prometheus/prometheus.yml'
volumes:
- ./prometheus:/etc/prometheus
extra_hosts:
host.docker.internal: host-gateway
grafana:
container_name: grafana
image: grafana/grafana:latest
restart: always
ports:
- 3000:3000
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- ./grafana-data:/var/lib/grafana
- ./grafana-data/provisioning/:/etc/grafana/provisioning/
./prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: '라벨'
query_log_file: query_log_file.log
scrape_configs:
- job_name: "spring-actuator"
metrics_path: "/actuator/prometheus"
scrape_interval: 1s
static_configs:
- targets: [ "host.docker.internal:8090" ]
2. `http://localhost:3000` 접속하고, ID: admin, PW: admin 입력하기
3. `Update your password` 창이 뜬다면 입력폼 왼쪽 하단에 `Skip` 버튼 누르기
4. 왼쪽 상단에 `메뉴 > Connections > Data sources` 버튼 누르기
5. 화면 중앙에 `Add data source` 버튼 누르고 `Prometeus` 선택
6. `Connection` 입력창에 `http://prometheus:9090` 을 입력해 주고 쭉 내려서 `Save & test` 버튼 누르기
7. 정상적으로 연결이 됐다면 `메뉴 > Dashboards` 버튼 누르기
8. 오른쪽 상단에 `New` 버튼을 누르고 `Import` 선택
9. `URL or ID` 입력창에 `4701` 또는 `11378`을 입력하고 `Load` 버튼 누르기
10. 6번 과정에서 생성했던 `프로메테우스`와 연동시키기