😎요즘 도커를 공부하는 도중 김영한님의 강의 중에 배웠던 prometheus, grafana를 도커로 띄우고 스프링 부트를 연동시켜보고 싶은 생각이 들어 실행하게 되었다.
prometheus.yml을 작성하여 그라파나와 스프링 부트를 연동시킬 것이다. 방법은 아래와 같다.
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'grafana'
scrape_interval: 5s
static_configs:
- targets: ['grafana:3000']
- job_name: 'spring-actuator'
metrics_path: '/actuator/prometheus'
scrape_interval: 1s
static_configs:
- targets: [ '{your ip address}:8080' ]
🤔처음에 {your ip address}부분을 localhost로 적었다가 작동을 제대로 하지 않았는데 이유는 간단하다. 각 컨테이너에서 localhost 부분은 자기 자신을 가리키고 있기 때문이다.(현재 스프링 부트는 host에서 운영중인 상황이며 프로메테우스와 그라파나는 도커로 띄운 상황)
version: "3"
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
grafana:
image: grafana/grafana
ports:
- "3000:3000"
🥳volumes 부분을 통해 위에서 작성한 prometheus.yml로 바꿔주고 설정파일을 내가 작성한 파일로 변경하기 위해--config.file=/etc/prometheus/prometheus.yml
라는 명령어를 작성한다.
🫡해당 yml파일로 이동 후 docker-compose up -d
를 통해 띄운 후 localhost:9090으로 이동하여 프로메테우스가 잘 뜨는지 확인 (stat -> target으로 가서 모두 up상태인지 확인)
localhost:3000 으로 가서 그라파나도 잘 되는지 확인하기