Skip to content

Commit

Permalink
feat: 그라파나 대시보드 구성 (#74)
Browse files Browse the repository at this point in the history
* feat: 스프링 액츄에이터, 프로메테우스 설정

* fix: 테스트 파일 제거
  • Loading branch information
kimday0326 authored Apr 3, 2024
1 parent e9a73cb commit d6f5654
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ out/
*-secret.yml
**/src/main/generated/
#**/data.sql

/grafana
/prometheus
!/prometheus/prometheus.yml
!/prometheus/prometheus.rules.yml
1 change: 1 addition & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
implementation project(':core:core-infra-redis');
implementation project(':core:core-infra-kafka')
implementation project(':core:core-security')
runtimeOnly project(':support:monitoring')

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand Down
6 changes: 4 additions & 2 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
spring:
application:
name: api
profiles:
group:
"local": "db, security, secret, redis, kafka"
"dev": "db, security, secret, redis, kafka"
"local": "db, security, secret, redis, kafka, monitoring"
"dev": "db, security, secret, redis, kafka, monitoring"
default: local
server:
port: 8080
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private RequestMatcher[] requestPermitAll() {
List<RequestMatcher> requestMatchers = List.of(
antMatcher("/"),
antMatcher("/swagger-ui/**"),
antMatcher("/actuator/**"),
antMatcher("/v3/api-docs/**"),
antMatcher("/ws/**"),
antMatcher("/from/**"),
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ services:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock

prometheus:
image: prom/prometheus:v2.37.6
container_name: prometheus
volumes:
- ./prometheus/config:/etc/prometheus
- ./prometheus/volume:/prometheus
ports:
- "9090:9090"
command:
- '--web.enable-lifecycle'
- '--config.file=/etc/prometheus/prometheus.yml'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
restart: always

grafana:
image: grafana/grafana:9.4.7
container_name: grafana
ports:
- "3000:3000"
volumes:
- ./grafana/volume:/var/lib/grafana
restart: always
24 changes: 24 additions & 0 deletions prometheus/config/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
global:
scrape_interval: 15s
scrape_timeout: 15s
evaluation_interval: 2m

external_labels:
monitor: 'system-monitor'
query_log_file: query_log_file.log

rule_files:
- "rule.yml"

scrape_configs:
- job_name: "prometheus"
static_configs:
- targets:
- "prometheus:9090"
- job_name: "springboot"
metrics_path: "/actuator/prometheus"
scheme: 'http'
scrape_interval: 5s
static_configs:
- targets:
- "host.docker.internal:8080"
18 changes: 18 additions & 0 deletions prometheus/config/rule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
groups:
- name: system-monitor
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: page
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."

- alert: APIHighRequestLatency
expr: api_http_request_latencies_second{quantile="0.5"} > 1
for: 10m
annotations:
summary: "High request latency on {{ $labels.instance }}"
description: "{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)"
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ include 'core:core-infra-db'
include 'core:core-infra-kafka'
include 'core:core-infra-redis'
include 'core:core-security'
include 'support:monitoring'
5 changes: 5 additions & 0 deletions support/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 실행가능한 jar로 생성하는 옵션, main이 없는 라이브러리에서는 false로 비활성화함
bootJar { enabled = false }

// 외부에서 의존하기 위한 jar로 생성하는 옵션, main이 없는 라이브러리에서는 true로 비활성화함
jar { enabled = true }
11 changes: 11 additions & 0 deletions support/monitoring/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 실행가능한 jar로 생성하는 옵션, main이 없는 라이브러리에서는 false로 비활성화함
bootJar { enabled = false }

// 외부에서 의존하기 위한 jar로 생성하는 옵션, main이 없는 라이브러리에서는 true로 비활성화함
jar { enabled = true }

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Binary file not shown.
7 changes: 7 additions & 0 deletions support/monitoring/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
management:
endpoints:
web:
exposure:
include: prometheus, health, info
metrics:
tags:
application: ${spring.application.name}

0 comments on commit d6f5654

Please sign in to comment.