Skip to content

Commit

Permalink
feat : prometheus & grafana docker compose setting (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingLeeSeungHoon committed May 10, 2024
1 parent 907fbc3 commit 393f7c8
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 16 deletions.
53 changes: 40 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ services:
redis-master-1:
container_name: redis-master-1
image: redis:latest
network_mode: "host"
# network_mode: "host"
restart: always
ports:
- "7001:7001"
- "127.0.0.1:7001:7001"
volumes:
- ./redis-master-1.conf:/etc/redis-master-1.conf
command:
Expand All @@ -47,10 +47,10 @@ services:
redis-master-2:
container_name: redis-master-2
image: redis:latest
network_mode: "host"
# network_mode: "host"
restart: always
ports:
- "7002:7002"
- "127.0.0.1:7002:7002"
volumes:
- ./redis-master-2.conf:/etc/redis-master-2.conf
command:
Expand All @@ -59,10 +59,10 @@ services:
redis-master-3:
container_name: redis-master-3
image: redis:latest
network_mode: "host"
# network_mode: "host"
restart: always
ports:
- "7003:7003"
- "127.0.0.1:7003:7003"
volumes:
- ./redis-master-3.conf:/etc/redis-master-3.conf
command:
Expand All @@ -71,10 +71,10 @@ services:
redis-replica-1:
container_name: redis-replica-1
image: redis:latest
network_mode: "host"
# network_mode: "host"
restart: always
ports:
- "7004:7004"
- "127.0.0.1:7004:7004"
volumes:
- ./redis-replica-1.conf:/etc/redis-replica-1.conf
command:
Expand All @@ -83,10 +83,10 @@ services:
redis-replica-2:
container_name: redis-replica-2
image: redis:latest
network_mode: "host"
# network_mode: "host"
restart: always
ports:
- "7005:7005"
- "127.0.0.1:7005:7005"
volumes:
- ./redis-replica-2.conf:/etc/redis-replica-2.conf
command:
Expand All @@ -95,10 +95,10 @@ services:
redis-replica-3:
container_name: redis-replica-3
image: redis:latest
network_mode: "host"
# network_mode: "host"
restart: always
ports:
- "7006:7006"
- "127.0.0.1:7006:7006"
volumes:
- ./redis-replica-3.conf:/etc/redis-replica-3.conf
command:
Expand All @@ -108,7 +108,7 @@ services:
image: redis:latest
container_name: redis_cluster
platform: linux/arm64/v8
network_mode: "host"
# network_mode: "host"
command: redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-yes --cluster-replicas 1
depends_on:
- redis-master-1
Expand All @@ -118,7 +118,34 @@ services:
- redis-replica-2
- redis-replica-3

prometheus:
image: prom/prometheus
container_name: prometheus
# network_mode: "host"
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- "127.0.0.1:9090:9090"
restart: unless-stopped
volumes:
- ./prometheus:/etc/prometheus
- prom_data:/prometheus

grafana:
image: grafana/grafana
container_name: grafana
# network_mode: "host"
ports:
- "127.0.0.1:3000:3000"
restart: unless-stopped
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=grafana
volumes:
- ./grafana:/etc/grafana/provisioning/datasources

# 볼륨에 대한 실제 디렉토리 자동 생성
volumes:
mysql_data:
mongodb_data:
prom_data:
9 changes: 9 additions & 0 deletions grafana/datasource.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: 1

datasources:
- name: Prometheus
type: prometheus
url: http://prometheus:9090
isDefault: true
access: proxy
editable: true
4 changes: 4 additions & 0 deletions needeachother/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ dependencies {

// related spring web
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-validation'

// metric prometheus
implementation 'io.micrometer:micrometer-registry-prometheus'

// IOUtils
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NEOJwtAuthenticationFilter extends OncePerRequestFilter {
private final NEOUserRepository userRepository;
private final GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
private final NEOServletResponseWriter servletResponseWriter;
private static final String[] NO_CHECK_URLS = {"/login", "/oauth2/authorization/", "/docs/neo-api-guide.html", "/api/v1/oauth2/", "/favicon.ico", "/test", "/api/v1/post/"};
private static final String[] NO_CHECK_URLS = {"/login", "/oauth2/authorization/", "/docs/neo-api-guide.html", "/api/v1/oauth2/", "/favicon.ico", "/test", "/api/v1/post/", "/actuator"};

private static final String RE_ISSUE_ACCESS_TOKEN_URL = "/api/v1/token/reissue";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// URL별 권한 관리
.authorizeHttpRequests(requests -> requests
// 로그인 관련 URL 모두 허가
.requestMatchers("/login", "/oauth2/authorization/**", "/api/v1/oauth2/**").permitAll()
.requestMatchers("/login", "/oauth2/authorization/**", "/api/v1/oauth2/**", "/actuator/**").permitAll()
// API 개발 문서 URL 모두 허가
.requestMatchers("/docs/**").permitAll()
.requestMatchers("/api/v1/post/**").permitAll()
Expand Down
11 changes: 10 additions & 1 deletion needeachother/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ spring:
include:
- db
- oauth
- jwt
- jwt

management:
endpoints:
web:
exposure:
include: prometheus, health, info
# metrics:
# tags:
# application: "neo"
27 changes: 27 additions & 0 deletions prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets: []
scheme: http
timeout: 10s
api_version: v1
scrape_configs:
- job_name: prometheus
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9090
- job_name: springboot
metrics_path: /actuator/prometheus
scheme: http
scrape_interval: 5s
static_configs:
- targets: ["host.docker.internal:8080"]

0 comments on commit 393f7c8

Please sign in to comment.