Skip to content

Commit 5ebda8f

Browse files
authored
Merge pull request #146 from Dan-Chu/feature/monitoring
✨ [FEAT/#145] Prometheus & Grafana 구축
2 parents 487fce3 + ddbde07 commit 5ebda8f

File tree

6 files changed

+121
-6
lines changed

6 files changed

+121
-6
lines changed

.github/workflows/cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ jobs:
5151
token: ${{ secrets.GIT_ACTION_TOKEN }}
5252
submodules: true
5353

54-
- name: Copy docker-compose.yml to Server
54+
- name: Copy compose & prometheus.yml to Server
5555
uses: appleboy/scp-action@master
5656
with:
5757
host: ${{ secrets.SSH_HOST }}
5858
port: ${{ secrets.SSH_PORT }}
5959
username: ${{ secrets.SSH_USERNAME }}
6060
key: ${{ secrets.SSH_PRIVATE_KEY }}
61-
source: "docker-compose.yml"
61+
source: "docker-compose.yml,prometheus.yml"
6262
target: "~/app"
6363

6464
- name: Deploy on server

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ dependencies {
5959
// Flyway
6060
implementation 'org.flywaydb:flyway-core'
6161
implementation 'org.flywaydb:flyway-mysql'
62+
63+
// Grafana & Prometheus
64+
implementation 'org.springframework.boot:spring-boot-starter-actuator'
65+
implementation 'io.micrometer:micrometer-registry-prometheus'
6266
}
6367

6468
tasks.named('test') {

docker-compose.yml

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ services:
6666
depends_on:
6767
- app
6868
- dozzle
69+
- grafana
70+
- prometheus
6971
networks:
7072
- danchu-network
7173
restart: unless-stopped
@@ -74,9 +76,66 @@ services:
7476
image: amir20/dozzle:latest
7577
container_name: dozzle
7678
volumes:
77-
- /var/run/docker.sock:/var/run/docker.sock:ro # 로그 접근을 위한 도커 소켓 마운트
79+
- /var/run/docker.sock:/var/run/docker.sock:ro # 로그 접근을 위한 도커 소켓 마운트
7880
networks:
79-
- danchu-network
81+
- danchu-network
82+
restart: unless-stopped
83+
84+
grafana:
85+
image: grafana/grafana
86+
container_name: grafana
87+
environment:
88+
- GF_SERVER_ROOT_URL=https://grafana.danchu.site/
89+
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
90+
- GF_USERS_ALLOW_SIGN_UP=false
91+
volumes:
92+
- grafana-storage:/var/lib/grafana
93+
networks:
94+
- danchu-network
95+
restart: unless-stopped
96+
97+
prometheus:
98+
image: prom/prometheus:latest
99+
container_name: prometheus
100+
volumes:
101+
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
102+
networks:
103+
- danchu-network
104+
restart: unless-stopped
105+
106+
node-exporter:
107+
image: prom/node-exporter
108+
container_name: node-exporter
109+
command:
110+
- '--path.rootfs=/host'
111+
volumes:
112+
- '/:/host:ro,rslave'
113+
networks:
114+
- danchu-network
115+
restart: unless-stopped
116+
117+
mysqld-exporter:
118+
image: prom/mysqld-exporter:v0.14.0
119+
container_name: mysqld-exporter
120+
environment:
121+
- DATA_SOURCE_NAME=exporter:${MYSQL_EXPORTER_PASSWORD}@(mysql:3306)/danchu
122+
depends_on:
123+
mysql:
124+
condition: service_healthy
125+
networks:
126+
- danchu-network
127+
restart: unless-stopped
128+
129+
redis-exporter:
130+
image: oliver006/redis_exporter:v1.67.0
131+
container_name: redis-exporter
132+
environment:
133+
- REDIS_ADDR=redis:6379
134+
depends_on:
135+
redis:
136+
condition: service_healthy
137+
networks:
138+
- danchu-network
80139
restart: unless-stopped
81140

82141
networks:
@@ -85,4 +144,5 @@ networks:
85144

86145
volumes:
87146
mysql-data:
88-
redis-data:
147+
redis-data:
148+
grafana-storage:

prometheus.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
global:
2+
scrape_interval: 5s
3+
evaluation_interval: 5s
4+
scrape_timeout: 4s
5+
6+
scrape_configs:
7+
# Prometheus
8+
- job_name: 'prometheus'
9+
static_configs:
10+
- targets: ['prometheus:9090']
11+
labels:
12+
application: prometheus
13+
service: prometheus
14+
15+
# Spring Boot
16+
- job_name: 'danchu'
17+
metrics_path: /actuator/prometheus
18+
static_configs:
19+
- targets: ['app:8080']
20+
labels:
21+
application: danchu
22+
service: app
23+
component: spring-boot
24+
25+
# node-exporter
26+
- job_name: 'node-exporter'
27+
static_configs:
28+
- targets: ['node-exporter:9100']
29+
labels:
30+
application: danchu
31+
service: node-exporter
32+
33+
# MySQL
34+
- job_name: 'mysql'
35+
static_configs:
36+
- targets: ['mysqld-exporter:9104']
37+
labels:
38+
application: danchu
39+
service: mysql
40+
component: exporter
41+
42+
# Redis
43+
- job_name: 'redis'
44+
static_configs:
45+
- targets: ['redis-exporter:9121']
46+
labels:
47+
application: danchu
48+
service: redis
49+
component: exporter

src/main/java/com/likelion/danchu/global/config/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
5656
.permitAll()
5757
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**")
5858
.permitAll()
59+
.requestMatchers("/actuator/health", "/actuator/info", "/actuator/prometheus")
60+
.permitAll()
5961
.anyRequest()
6062
.authenticated())
6163
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);

src/main/resources

0 commit comments

Comments
 (0)