메트릭 수집, 시각화, 알림, 서비스 디스커버리 기능을 모두 가지고 있는 오픈소스 모니터링 툴이다.
시계열 데이터 수집하고 저장하는 데 사용된다. 이 값은 레이블이라는 Key-Value 쌍으로 타임스탬프와 함께 저장되어 시계열 데이터가 형상화된다.
지금은 독립형 오픈소스 프로젝트이며 많은 회사들이 사용 하고 있고, 또한 kubernetes에서도 Prometheus를 사용하여 매트릭 수집 및 대시보드 구축하는 방식을 장려하고 있다.
시계열 데이터란 일정한 시간 동안 수집 된 일련의 순차적으로 정해진 데이터 셋의 집합입니다. 시계열 데이터의 특징으로는 시간에 관해 순서가 매겨져 있다는 점과, 연속한 관측치는 서로 상관관계를 갖고 있습니다.

docker-compose up -d
version: '2.14.0'
services:
prometheus:
container_name: prometheus
image: 'prom/prometheus:latest'
user: root
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- '9090:9090'
networks:
- monitor-net
restart: unless-stopped
grafana:
container_name: grafana
image: 'grafana/grafana:latest'
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false
ports:
- '3000:3000'
depends_on:
- prometheus
networks:
- monitor-net
restart: unless-stopped
networks:
monitor-net:
name: monitor-net
driver: bridge
# 기본적인 전역 설정
global:
scrape_interval: 15s # 15초마다 매트릭을 수집 default 1분
evaluation_interval: 1m # 1분마다 규칙을 평가 default 1분
external_labels: # 외부 시스템에 표시할 이 서버의 레이블
monitor: 'jinhyung-monitor'
scrape_configs:
- job_name: 'monitoring-app' # 잡 이름
metrics_path: '/actuator/prometheus' # 메트릭을 수집할 path 설정
static_configs:
- targets: [ 'host.docker.internal:8080' ] # 도커 인스턴스 내부 호스트:8080
prometheus 콘솔 접속

grafana dashboard 접속





<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
management:
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: health, info, metrics, prometheus
metrics:
tags:
application: ${spring.application.name}
application 구동

Actuator 확인

prometheus metric 확인
prometheus 콘솔에서 “jvm_memory_used_bytes” 입력 후 [Execute] 클릭

Grafana 콘솔에서 “jvm_memory_used_bytes” 선택 후 [Run query] 클릭

springboot 검색 후 마음에 드는 template 클릭

ID를 복사해서 사용하는 방법이 있고, JSON 파일을 받아서 사용하는 방법이 있다.
간단하게 ID를 복사해서 import 진행
[Copy ID to clipboard] 클릭

나의 grafana dashboard 화면으로 와서 New-Import 클릭

아까 복사한 ID를 넣고 Load 버튼을 클릭

알아서 Dashboard template을 불러온다.

멋진 APM 이 완성되었다.

Custom Metric 추가



(CASE2) 해당 코드 부분이 실행되도록 API 호출
조회 결과

PromQL 활용

현재 사용중인 grafana에 아래 사진처럼 alert이 등록되어있으며, 설정한 임계치가 초과하는 경우 Teams의 “[Notification] - [ERROR] 코어개발-백오피스개발팀” 채널로 메시지가 발송되고 있음