inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

프로메테우스 - 수집 설정

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

해결된 질문

1839

Dabi

작성한 질문수 8

5

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

 

감사합니다.

 

spring spring-boot prometheus grafana

답변 2

0

David

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

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

0

인프런 AI 인턴

안녕하세요, 인프런 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의 설정에 대한 더 많은 정보를 얻을 수 있을 거예요.

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

보안이 엄격한 데이터

0

71

1

MyProperties 자체를 클라이언트 코드에서 사용

1

42

1

http://localhost:8080/actuator/prometheus

0

84

3

jar 추가에대한 질문드려도될까요?

0

62

1

build.gradle bom link 변경

0

63

2

@Counted 초기화

0

47

1

@Validated를 적용해도 빈 검증이 안되는 경우에 대한 조치 공유..

0

99

2

springboot에서 actuator없이 micrometer를 사용할수 있나요?

0

67

1

@Configuration 질문드립니다.

0

84

2

[공유] 터미널 말고 IDE 에서 jar 실행하기

0

97

1

localhost:8080/hello-servlet 404오류

0

123

2

내장톰캣2 서블릿 톰켓 실행이 안됩니다

1

152

2

최대 Tomcat 스레드 수를 확인하는 지표

0

159

1

mac m2에서 startup.sh 실행후 아무 반응이 없습니다.

0

94

2

내장 톰캣 실행 오류 관련 질문드립니다.

0

156

1

스프링 발전 과정들도 자세히 알아둬야하나요??

1

126

1

스프링부트 ioc 컨테이너 갯수

0

89

1

404 페이지

0

133

3

actuator 호출시 타임스탬프 질문

0

90

1

순수 라이브러리 사용하기 2 - memory-v1

0

124

1

외부설정 @ConfigurationProperties의 내부 클래스에서 static을 사용하는 이유를 알고 싶습니다.

0

103

1

서블릿 컨테이너 초기화1 강의 관련 질문입니다~

0

90

1

Thread Config Max 패널 설정 변경 질문

0

123

1

스프링 액츄에이터 shutdown 엔드포인트 활성화가 안됩니다.

0

103

1