Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

.env
*.env

### STS ###
.apt_generated
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ dependencies {
// validator
implementation 'commons-validator:commons-validator:1.7'

// actuator
implementation 'org.springframework.boot:spring-boot-starter-actuator'

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

}

tasks.named('test') {
Expand Down
3 changes: 3 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
- moplus-dev
- nginx-network
- apm_env
- monitoring

mysql:
image: mysql:8.0
Expand All @@ -55,6 +56,8 @@ volumes:
networks:
moplus-dev:
driver: bridge
monitoring:
driver: bridge
nginx-network:
external: true
apm_env:
Expand Down
74 changes: 74 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: "3"
services:

prometheus:
image: prom/prometheus
container_name: prometheus
volumes:
- ./src/main/resources/prometheus.yml:/etc/prometheus/prometheus.yml
environment:
PROMETHEUS_SCRAPE_INTERVAL: ${PROMETHEUS_SCRAPE_INTERVAL}
PROMETHEUS_TARGET_BACKEND: ${PROMETHEUS_TARGET_BACKEND}
ports:
- "9090:9090"
networks:
- monitoring

grafana:
image: grafana/grafana:9.4.7
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana-volume:/var/lib/grafana
restart: always
networks:
- monitoring
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_SECURITY_ADMIN_USER=admin
user: "472"

loki:
image: grafana/loki:2.8.2
container_name: loki
ports:
- "3100:3100"
volumes:
- ./loki-data:/var/lib/loki
- ./loki-config.yml:/etc/loki/config.yml
environment:
LOKI_PORT: ${LOKI_PORT}
networks:
- monitoring

promtail:
image: grafana/promtail:2.8.2
container_name: promtail
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./promtail-config.yml:/etc/promtail/config.yml
environment:
PROMTAIL_PORT: ${PROMTAIL_PORT}
depends_on:
- loki
networks:
- monitoring

networks:
monitoring:
driver: bridge

volumes:
grafana-volume:
driver: local
driver_opts:
type: none
o: bind
device: ./grafana/volume
loki-data:
driver: local
driver_opts:
type: none
o: bind
device: ./loki-data
45 changes: 45 additions & 0 deletions loki-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
server:
http_listen_port: 3100

ingester:
wal:
enabled: true
dir: /var/lib/loki/wal
lifecycler:
address: 0.0.0.0
ring:
kvstore:
store: inmemory
replication_factor: 1

compactor:
working_directory: /var/lib/loki/compactor
shared_store: filesystem
retention_enabled: true

schema_config:
configs:
- from: 2022-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h

storage_config:
boltdb_shipper:
active_index_directory: /var/lib/loki/index
shared_store: filesystem
cache_location: /var/lib/loki/cache

limits_config:
reject_old_samples: true
reject_old_samples_max_age: 168h

chunk_store_config:
max_look_back_period: 168h

table_manager:
retention_deletes_enabled: true
retention_period: 168h
28 changes: 28 additions & 0 deletions promtail-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server:
http_listen_port: 9080

positions:
filename: /var/lib/promtail/positions.yaml

clients:
- url: http://loki:3100/loki/api/v1/push
batchwait: 5s
batchsize: 512000

scrape_configs:
- job_name: "docker-logs"
docker_sd_configs:
- host: unix:///var/run/docker.sock
refresh_interval: 5s
relabel_configs:
- source_labels: [__meta_docker_container_name]
regex: "moplus-server-dev"
action: keep

- source_labels: [__meta_docker_container_name]
regex: "/(.+)"
target_label: container

- source_labels: [container]
target_label: job
replacement: "moplus-server-dev-logs"
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SecurityConfig {
private final EmailPasswordSuccessHandler emailPasswordSuccessHandler;
private final AuthenticationConfiguration authenticationConfiguration;

private String[] allowUrls = {"/", "/favicon.ico", "/swagger-ui/**", "/v3/**"};
private String[] allowUrls = {"/", "/favicon.ico", "/swagger-ui/**", "/v3/**", "/actuator/**"};

@Value("${cors-allowed-origins}")
private List<String> corsAllowedOrigins;
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/application-monitoring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
management:
endpoints:
web:
exposure:
include: "prometheus,health,info"
health:
show-details: always
metrics:
export:
prometheus:
enabled: true
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spring:
include:
- aws
- security
- monitoring
mvc:
ignore-default-favicon: true

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
global:
scrape_interval: 5s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'moplus_server'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['back:8080']