Skip to content

Commit f597164

Browse files
authored
Merge pull request #56 from Dalguring/feature/monitoring
feature: PLG + Prometheus 통합 모니터링 환경 구축
2 parents cb4459c + ac26c57 commit f597164

File tree

10 files changed

+122
-3
lines changed

10 files changed

+122
-3
lines changed

.github/workflows/github-actions-rentify-api.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ jobs:
5050
tags: |
5151
${{ secrets.DOCKERHUB_USERNAME }}/universal-device-rental:latest
5252
53-
- name: Copy docker-compose.yml to GCP
53+
- name: Copy files to GCP
5454
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
5555
uses: appleboy/scp-action@v1
5656
with:
5757
host: ${{ secrets.GCP_HOST }}
5858
username: ${{ secrets.GCP_USERNAME }}
5959
key: ${{ secrets.GCP_SSH_KEY }}
60-
source: "docker-compose.yml"
60+
source: "docker-compose.yml,monitoring/**"
6161
target: "/home/${{ secrets.GCP_USERNAME }}/ecommerce-project/infra"
6262

6363
- name: Deploy to GCP

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ out/
4747

4848
### Run File ###
4949
/start-tunnel.*
50+
51+
### Log File ###
52+
/logs

docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
- "80:8080"
3333
volumes:
3434
- upload_data:/app/uploads
35+
- app_logs:/app/logs
3536
environment:
3637
TZ: Asia/Seoul
3738
SPRING_PROFILES_ACTIVE: dev
@@ -50,13 +51,54 @@ services:
5051
MAIL_USERNAME: ${MAIL_USERNAME}
5152
MAIL_PASSWORD: ${MAIL_PASSWORD}
5253

54+
LOGGING_FILE_NAME: /app/logs/application.log
55+
5356
JAVA_OPTS: >-
5457
-Duser.timezone=Asia/Seoul
5558
-Xms512m
5659
-Xmx512m
5760
-XX:+UseG1GC
5861
-XX:MaxGCPauseMillis=200
5962
63+
prometheus:
64+
image: prom/prometheus:latest
65+
container_name: prometheus
66+
volumes:
67+
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
68+
command:
69+
- '--config.file=/etc/prometheus/prometheus.yml'
70+
71+
loki:
72+
image: grafana/loki:latest
73+
container_name: loki
74+
volumes:
75+
- ./monitoring/loki-config.yaml:/etc/loki/local-config.yaml
76+
command: -config.file=/etc/loki/local-config.yaml
77+
78+
promtail:
79+
image: grafana/promtail:latest
80+
container_name: promtail
81+
volumes:
82+
- ./monitoring/promtail-config.yaml:/etc/promtail/config.yml
83+
- app_logs:/app/logs:ro
84+
command: -config.file=/etc/promtail/config.yml
85+
86+
grafana:
87+
image: grafana/grafana:latest
88+
container_name: grafana
89+
ports:
90+
- "3000:3000"
91+
environment:
92+
- GF_SECURITY_ADMIN_USER=admin
93+
- GF_SECURITY_ADMIN_PASSWORD=admin
94+
depends_on:
95+
- prometheus
96+
- loki
97+
volumes:
98+
- grafana_data:/var/lib/grafana
99+
60100
volumes:
61101
postgres_data:
62102
upload_data:
103+
app_logs:
104+
grafana_data:

monitoring/loki-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
auth_enabled: false
2+
3+
server:
4+
http_listen_port: 3100
5+
6+
common:
7+
path_prefix: /loki
8+
storage:
9+
filesystem:
10+
chunks_directory: /loki/chunks
11+
rules_directory: /loki/rules
12+
replication_factor: 1
13+
ring:
14+
kvstore:
15+
store: inmemory
16+
17+
schema_config:
18+
configs:
19+
- from: 2020-10-24
20+
store: boltdb-shipper
21+
object_store: filesystem
22+
schema: v11
23+
index:
24+
prefix: index_
25+
period: 24h

monitoring/prometheus.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global:
2+
scrape_interval: 5s
3+
4+
scrape_configs:
5+
- job_name: 'rentify-api'
6+
metrics_path: '/actuator/prometheus'
7+
static_configs:
8+
- targets: ['spring:8080']

monitoring/promtail-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
server:
2+
http_listen_port: 9000
3+
grpc_listen_port: 0
4+
5+
positions:
6+
filename: /tmp/positions.yaml
7+
8+
clients:
9+
- url: http://loki:3100/loki/api/v1/push
10+
11+
scrape_configs:
12+
- job_name: system
13+
static_configs:
14+
- targets:
15+
- localhost
16+
labels:
17+
job: rentify-api-logs
18+
__path__: /app/logs/*.log

src/main/java/com/rentify/rentify_api/common/config/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
4545
.httpBasic(AbstractHttpConfigurer::disable)
4646
.authorizeHttpRequests(auth -> auth
4747
.requestMatchers(SWAGGER_WHITELIST).permitAll()
48+
.requestMatchers("/actuator/**").permitAll()
4849
// User API
4950
.requestMatchers(HttpMethod.POST, "/api/users").permitAll()
5051
.requestMatchers(HttpMethod.POST, "/api/users/login").permitAll()

src/main/resources/application-dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ logging:
2929
root: INFO
3030
com.rentify.rentify_api: INFO
3131
org.hibernate.SQL: ERROR
32+
file:
33+
name: /app/logs/application.log
3234

3335
file:
3436
upload:

src/main/resources/application-local.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ logging:
2929
root: INFO
3030
com.rentify.rentify_api: DEBUG
3131
org.hibernate.SQL: DEBUG
32+
file:
33+
name: logs/application-local.log
3234

3335
file:
3436
upload:

src/main/resources/application.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,22 @@ file:
5959
upload:
6060
path: ${FILE_UPLOAD_PATH}
6161
base:
62-
url: ${FILE_BASE_URL}
62+
url: ${FILE_BASE_URL}
63+
64+
management:
65+
endpoints:
66+
web:
67+
exposure:
68+
include: prometheus, health, info, metrics
69+
endpoint:
70+
health:
71+
show-details: always
72+
metrics:
73+
tags:
74+
application: ${spring.application.name}
75+
76+
logging:
77+
logback:
78+
rollingpolicy:
79+
max-history: 7
80+
max-file-size: 10MB

0 commit comments

Comments
 (0)