loose
이로운 개발하기
loose
전체 방문자
오늘
어제
  • 전체 (205)
    • ☕ Java (24)
    • 📘 Effective Java (9)
    • 🍃 Spring (48)
    • 📖 ORM (9)
    • ☸️ Kubernetes (13)
    • 🐧 Linux (5)
    • 🐋 Docker (5)
    • 🛠️ CI & CD (7)
    • 🕸️ Web (6)
    • 🔗 Distributed System (3)
    • 📜 Js (10)
    • 📈 Database (11)
    • 🗂️ Etc (34)
    • 🧑 Chitchat (11)
    • 📒 문학 (9)
    • 👜 개인 공부 창고 (1)

공지사항

반응형

최근 글

최근 댓글

loose
🍃 Spring

Spring Actuator + Prometheus + Grafana

Spring Actuator + Prometheus + Grafana
🍃 Spring

Spring Actuator + Prometheus + Grafana

2023. 8. 13. 13:38
반응형

이전에 Actuator로 무식하게 데이터를 확인했다면 이제는 위의 두 서버를 받아서 로그를 시각화해서 보자!

아래는 윈도우 기준이지만 크게 상관없다.

 

연결 샘플 프로젝트는 아래 깃헙을 참조.

 

GitHub - stir084/spring-grafana-prometheus: grafana-prometheus sample

grafana-prometheus sample. Contribute to stir084/spring-grafana-prometheus development by creating an account on GitHub.

github.com

https://refactorfirst.com/spring-boot-prometheus-grafana

설치

https://grafana.com/grafana/download?platform=windows
https://prometheus.io/download/

Prometheus 설정

promethous.yml 파일에 아래 내용 추가

scrape_configs:
  - job_name: 'spring--app'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['host.docker.internal:8080']

Prometheus 서버 실행

설치 폴더 prometheus-2.46.0.windows-amd64 밑에 prometheus.exe 실행
localhost:9090으로 접속 가능

grafana 서버 실행

powershell 에서 C:\Program Files\GrafanaLabs\grafana\bin> .\grafana-server.exe
localhost:3000으로 접속 가능
초기비번은 admin admin

백엔드 설정

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.micrometer:micrometer-registry-prometheus'
management.endpoints.web.exposure.include=*
server.tomcat.mbeanregistry.enabled=true
management.endpoint.health.show-details=always

management.prometheus.metrics.export.enabled=true
management.metrics.export.prometheus.path=/prometheus

3개의 서버가 잘 붙었는지 확인하기

backend <-> prometheus

http://localhost:8080/actuator/prometheus 으로 접속이 되면 prometheous 로그가 잘 보인다.
localhost:9090에 들어가서 status -> target으로 들어가서 Prometheus 서버와 백엔드 서버가 연결되어 있는지 확인한다.
연결 상태가 up인 경우에 잘 붙은 것이며 좌측 주소를 클릭하면 위에 http://localhost:8080/actuator/prometheus에 접속한 것과 동일한 로그가 보인다.

prometheus <-> grafana

grafana에서 초기 화면에서 Add you first Datasource 클릭
Prometheus 클릭 후 url에 http://host.docker.internal:9090/ 입력한다.
우측 위 상단에 import dashboard로 id가 4701인 대쉬보드를 검색 후 만들어놓은 datasource를 추가하면 완료.

스레드 개수 확인

peak은 최고 스레드 개수
live는 살아있는 스레드 개수
deamon은 백그라운드에서 보조 작업을 수행하는 스레드(GC, 메모리 관리 등)
즉, live 개수에 deamon 개수를 빼면 요청자가 대충 몇명인지 알 수도 있다.

728x90

'🍃 Spring' 카테고리의 다른 글

JUnit 문법  (0) 2023.08.26
@WebMvcTest에 대한 올바른 사용법 및 시행착오  (0) 2023.08.22
Spring Actuator와 Thread(+@Scheduled)  (0) 2023.08.12
@Transactional을 테스트에 써야할까?  (0) 2023.07.23
@JsonProperty 사용법에 대한 모든 것  (2) 2023.07.09
  • 설치
  • Prometheus 설정
  • Prometheus 서버 실행
  • grafana 서버 실행
  • 백엔드 설정
  • 3개의 서버가 잘 붙었는지 확인하기
  • backend <-> prometheus
  • prometheus <-> grafana
  • 스레드 개수 확인
'🍃 Spring' 카테고리의 다른 글
  • JUnit 문법
  • @WebMvcTest에 대한 올바른 사용법 및 시행착오
  • Spring Actuator와 Thread(+@Scheduled)
  • @Transactional을 테스트에 써야할까?
loose
loose
불만하는 사람은 90명, 해결하는 사람은 9명, 리드하는 사람은 1명
음악과 낭만을 좋아합니다.
hELLO. 티스토리 스킨을 소개합니다.
제일 위로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.