Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 프로메테우스, 그라파나 컴포즈 추가 #31

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sns_service/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ out/
# Ignore redis binary dump (dump.rdb) files

*.rdb

### prometheus ###
prometheus/config/**.log
prometheus/volume/data/

### grafana ###
grafana/
46 changes: 24 additions & 22 deletions sns_service/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "3.1.2"
id("io.spring.dependency-management") version "1.1.2"
kotlin("jvm") version "1.8.22"
kotlin("plugin.spring") version "1.8.22"
id("org.springframework.boot") version "3.1.2"
id("io.spring.dependency-management") version "1.1.2"
kotlin("jvm") version "1.8.22"
kotlin("plugin.spring") version "1.8.22"
}

group = "2joryu"
version = "0.0.1-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
}

configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation ("org.springframework.boot:spring-boot-starter-data-jpa")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
runtimeOnly("com.mysql:mysql-connector-j")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-registry-prometheus")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
runtimeOnly("com.mysql:mysql-connector-j")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "17"
}
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "17"
}
}

tasks.withType<Test> {
useJUnitPlatform()
useJUnitPlatform()
}
24 changes: 24 additions & 0 deletions sns_service/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@ services:
MYSQL_DATABASE: sns-db
MYSQL_ROOT_PASSWORD: 1234
command: [ '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]

prometheus:
image: "prom/prometheus:v2.47.0"
container_name: prometheus
volumes:
- ./prometheus/config:/etc/prometheus
- ./prometheus/volume:/prometheus
ports:
- "9091:9090"
command:
- '--web.enable-lifecycle' # api 재시작없이 설정파일들을 reload 할 수 있게 해줌
- '--config.file=/etc/prometheus/prometheus.yaml'
- '--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:
- "3001:3000"
volumes:
- ./grafana/volume:/var/lib/grafana
restart: always
24 changes: 24 additions & 0 deletions sns_service/prometheus/config/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
global:
scrape_interval: 15s # scrap target의 기본 interval을 15초로 변경 / default = 1m
scrape_timeout: 15s # scrap request 가 timeout 나는 길이 / default = 10s
evaluation_interval: 2m # rule 을 얼마나 빈번하게 검증하는지 / default = 1m

external_labels:
monitor: 'ktwitter-monitor' # 기본적으로 붙여줄 라벨
query_log_file: query_log_file.log # prometheus의 쿼리 로그들을 기록, 없으면 기록안함

rule_files:
- "rule.yml" # 파일 위치는 prometheus.yaml 이 있는 곳과 동일 위치

scrape_configs:
- job_name: "prometheus"
static_configs:
- targets:
- "localhost:9090"
- job_name: "springboot"
metrics_path: "/actuator/prometheus"
scheme: 'http'
scrape_interval: 5s
static_configs:
- targets:
- "localhost:8080"
18 changes: 18 additions & 0 deletions sns_service/prometheus/config/rule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
groups:
- name: ktwitter
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)"
6 changes: 6 additions & 0 deletions sns_service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ spring:
show_sql: true
format_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect

management:
endpoints:
web:
exposure:
include: "prometheus"