Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit 40af7be

Browse files
author
trzysiek
committed
health checks for everything work
1 parent 2047953 commit 40af7be

File tree

2 files changed

+127
-4
lines changed

2 files changed

+127
-4
lines changed

docker-compose.yml

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
version: '3.8'
22

3+
######################
4+
# APPS (microservices)
5+
# - service1
6+
# - service2
7+
# - health-monitor
8+
39
services:
410
service1:
511
build: ./service1
612
container_name: service1
713
ports:
814
- "5001:5001"
915
networks:
10-
- microservices-network
16+
- grafana_network
1117
healthcheck:
1218
test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
1319
interval: 30s
@@ -20,7 +26,7 @@ services:
2026
ports:
2127
- "5002:5002"
2228
networks:
23-
- microservices-network
29+
- grafana_network
2430
healthcheck:
2531
test: ["CMD", "curl", "-f", "http://localhost:5002/health"]
2632
interval: 30s
@@ -33,7 +39,7 @@ services:
3339
ports:
3440
- "5000:5000"
3541
networks:
36-
- microservices-network
42+
- grafana_network
3743
depends_on:
3844
- service1
3945
- service2
@@ -43,6 +49,102 @@ services:
4349
- MAX_RETRIES=3 # Max consecutive failures before marking as down
4450
restart: unless-stopped
4551

52+
######################
53+
# MONITORING
54+
# - loki
55+
# - prometheus
56+
# - grafana
57+
58+
prometheus:
59+
image: prom/prometheus:latest
60+
container_name: prometheus
61+
ports:
62+
- "9090:9090"
63+
volumes:
64+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
65+
- prometheus_data:/prometheus
66+
command:
67+
- '--config.file=/etc/prometheus/prometheus.yml'
68+
- '--storage.tsdb.path=/prometheus'
69+
- '--web.console.libraries=/etc/prometheus/console_libraries'
70+
- '--web.console.templates=/etc/prometheus/consoles'
71+
- '--storage.tsdb.retention.time=200h'
72+
- '--web.enable-lifecycle'
73+
healthcheck:
74+
test: ["CMD", "curl", "-f", "http://localhost:9090/-/healthy"]
75+
interval: 30s
76+
timeout: 10s
77+
retries: 3
78+
networks:
79+
- grafana_network
80+
81+
grafana:
82+
image: grafana/grafana:12.0.2
83+
container_name: grafana
84+
ports:
85+
- "3000:3000"
86+
environment:
87+
- GF_AUTH_ANONYMOUS_ENABLED=true
88+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
89+
- GF_AUTH_DISABLE_LOGIN_FORM=true
90+
- GF_USERS_ALLOW_SIGN_UP=false
91+
volumes:
92+
- grafana_data:/var/lib/grafana
93+
- ./grafana/provisioning:/etc/grafana/provisioning
94+
healthcheck:
95+
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
96+
interval: 30s
97+
timeout: 10s
98+
retries: 3
99+
depends_on:
100+
- prometheus
101+
networks:
102+
- grafana_network
103+
104+
loki:
105+
image: grafana/loki:latest
106+
container_name: loki
107+
ports:
108+
- "3100:3100"
109+
volumes:
110+
- ./loki:/etc/loki
111+
- loki_data:/loki
112+
command: -config.file=/etc/loki/loki.yml
113+
healthcheck:
114+
test: ["CMD", "curl", "-f", "http://localhost:3100/ready"]
115+
interval: 30s
116+
timeout: 10s
117+
retries: 3
118+
networks:
119+
- grafana_network
120+
121+
# Example microservice with metrics endpoint
122+
metrics_generator:
123+
image: prom/node-exporter:latest
124+
container_name: example_metrics
125+
ports:
126+
- "9100:9100"
127+
networks:
128+
- grafana_network
129+
130+
log-generator:
131+
build:
132+
context: ./log-generator
133+
dockerfile: Dockerfile
134+
container_name: log-generator
135+
networks:
136+
- grafana_network
137+
depends_on:
138+
- loki
139+
140+
volumes:
141+
grafana_data:
142+
driver: local
143+
prometheus_data:
144+
driver: local
145+
loki_data:
146+
driver: local
147+
46148
networks:
47-
microservices-network:
149+
grafana_network:
48150
driver: bridge

health-monitor/monitor.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@
2222
'last_check': None,
2323
'last_response_time': None,
2424
'consecutive_failures': 0
25+
},
26+
'prometheus': {
27+
'url': 'http://prometheus:9090/-/healthy',
28+
'status': 'unknown',
29+
'last_check': None,
30+
'last_response_time': None,
31+
'consecutive_failures': 0
32+
},
33+
'grafana': {
34+
'url': 'http://grafana:3000/api/health',
35+
'status': 'unknown',
36+
'last_check': None,
37+
'last_response_time': None,
38+
'consecutive_failures': 0
39+
},
40+
'loki': {
41+
'url': 'http://loki:3100/ready',
42+
'status': 'unknown',
43+
'last_check': None,
44+
'last_response_time': None,
45+
'consecutive_failures': 0
2546
}
2647
}
2748

0 commit comments

Comments
 (0)