인프런 커뮤니티 질문&답변

Dabi님의 프로필 이미지

작성한 질문수

스프링 부트 - 핵심 원리와 활용

프로메테우스 - 수집 설정

docker로 prometheus, grafana 사용하는 경우 설정 가이드

해결된 질문

23.09.29 01:20 작성

·

1.4K

·

수정됨

4

prometheus.yml

 

global:
  scrape_interval: 15s
  evaluation_interval: 15s
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093
rule_files:
scrape_configs:
  - job_name: "docker"
    static_configs:
      - targets: ["localhost:9090"]
    #추가
  - job_name: "spring-actuator"
    metrics_path: '/actuator/prometheus'
    scrape_interval: 1s
    static_configs:
    - targets: ['host.docker.internal:8080']

targetslocalhost:8080으로 하면 안됩니다. ㅠㅠ

 

targetslocalhost:8080으로 하면 아래와 같은 결과가 나옵니다.

 

반드시 targets: ['host.docker.internal:8080']로 설정해 주세요!

 

docker-compose.yml

version: '3'
services:
  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: always
    ports:
      - "3000:3000"
    volumes:
      - grafana-data:/var/lib/grafana
      - ./grafana/provisioning/:/etc/grafana/provisioning/
    environment:
      - GF_SERVER_ROOT_URL=http://localhost:3000
      - GF_SECURITY_ADMIN_PASSWORD=admin
    depends_on:
      - prometheus

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: always
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus/config:/etc/prometheus/
      - prometheus-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'

volumes:
  grafana-data:
  prometheus-data:

 

결과

http://localhost:9090/targets

 

감사합니다.

 

답변 2

0

David님의 프로필 이미지

2023. 10. 01. 20:03

안녕하세요. Dabi님, 공식 서포터즈 David입니다.

공유해 주셔서 감사합니다.

0

인프런 AI 인턴님의 프로필 이미지

2023. 10. 01. 01:26

안녕하세요, 인프런 AI 인턴이에요.

Dabi님의 질문을 보면서 docker를 이용해 prometheus와 grafana를 설정하는 방법에 대해 알려드릴게요.

먼저, prometheus.yml 파일의 설정을 살펴보면 job_name이 “docker”와 “spring-actuator”로 정의되어 있습니다. “docker”는 localhost의 9090포트로 스크랩(push)을 수행하고, “spring-actuator”는 host.docker.internal의 8080포트로 스크랩을 수행합니다. 이 부분에서 targets는 [‘host.docker.internal:8080’]로 설정되어야 합니다. 만약 localhost:8080으로 설정하게 되면 원하는 결과가 나오지 않을 수 있습니다.

또한, docker-compose.yml 파일을 살펴보면 grafana와 prometheus 서비스가 정의되어 있습니다. grafana는 grafana/grafana:latest 이미지를 사용하며, 포트 3000번으로 접속 가능합니다. 이 때, GF_SERVER_ROOT_URL을 localhost:3000으로 설정하고, GF_SECURITY_ADMIN_PASSWORD를 admin으로 설정하였습니다. prometheus는 prom/prometheus:latest 이미지를 사용하며, 포트 9090번으로 접속 가능합니다. 설정 파일은 ./prometheus/config 폴더에 위치하고 있습니다.

이제 docker-compose.yml 파일을 사용하여 prometheus와 grafana를 실행할 수 있습니다. 파일이 위치한 디렉토리에서 터미널을 열고 docker-compose up -d 명령어를 실행하면 서비스가 시작됩니다.

이제 prometheus는 http://localhost:9090, grafana는 http://localhost:3000에서 접속이 가능하며, 설정한 대로 데이터를 수집하고 시각화할 수 있게 됩니다.

더 자세한 내용은 참고 링크를 확인해보세요. 이 링크에서는 prometheus와 grafana의 설정에 대한 더 많은 정보를 얻을 수 있을 거예요.

질문이 더 있으시다면 언제든지 물어보세요. 즐거운 개발되세요!

Dabi님의 프로필 이미지

작성한 질문수

질문하기