Skip to content

Commit bda8880

Browse files
rayhan1967rayhan1967
authored andcommitted
πŸ” Version 3.0: Complete Observability & Security Stack
✨ Monitoring & Observability: - Prometheus metrics collection for all services - Grafana dashboards for real-time visualization - ELK Stack (Elasticsearch + Logstash + Kibana) for centralized logging - Performance metrics with histogram and counters - Custom alerting rules and notifications πŸ” Security & Performance: - Redis-based distributed rate limiting - API security middleware with Helmet.js - Performance monitoring with response time tracking - Request/response logging and correlation IDs - Error tracking and alerting system πŸ—οΈ Infrastructure: Production-ready monitoring stack πŸ“Š Observability: Complete metrics, logs, and traces ecosystem
1 parent 6503d18 commit bda8880

File tree

6 files changed

+201
-0
lines changed

6 files changed

+201
-0
lines changed

β€Ždocker-compose.ymlβ€Ž

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,78 @@ volumes:
4444
networks:
4545
microservices-network:
4646
driver: bridge
47+
48+
prometheus:
49+
image: prom/prometheus:latest
50+
container_name: prometheus
51+
ports:
52+
- "9090:9090"
53+
volumes:
54+
- ./monitoring/prometheus:/etc/prometheus
55+
command:
56+
- '--config.file=/etc/prometheus/prometheus.yml'
57+
- '--storage.tsdb.path=/prometheus'
58+
- '--web.console.libraries=/etc/prometheus/console_libraries'
59+
- '--web.console.templates=/etc/prometheus/consoles'
60+
networks:
61+
- microservices-network
62+
63+
grafana:
64+
image: grafana/grafana:latest
65+
container_name: grafana
66+
ports:
67+
- "3013:3000"
68+
environment:
69+
- GF_SECURITY_ADMIN_PASSWORD=admin123
70+
volumes:
71+
- grafana-storage:/var/lib/grafana
72+
- ./monitoring/grafana:/etc/grafana/provisioning
73+
networks:
74+
- microservices-network
75+
76+
volumes:
77+
grafana-storage:
78+
79+
elasticsearch:
80+
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
81+
container_name: elasticsearch
82+
environment:
83+
- discovery.type=single-node
84+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
85+
- xpack.security.enabled=false
86+
ports:
87+
- "9200:9200"
88+
volumes:
89+
- elasticsearch_data:/usr/share/elasticsearch/data
90+
networks:
91+
- microservices-network
92+
93+
logstash:
94+
image: docker.elastic.co/logstash/logstash:8.11.0
95+
container_name: logstash
96+
ports:
97+
- "5044:5044"
98+
- "9600:9600"
99+
volumes:
100+
- ./monitoring/logstash:/usr/share/logstash/pipeline
101+
environment:
102+
- "LS_JAVA_OPTS=-Xmx256m -Xms256m"
103+
networks:
104+
- microservices-network
105+
depends_on:
106+
- elasticsearch
107+
108+
kibana:
109+
image: docker.elastic.co/kibana/kibana:8.11.0
110+
container_name: kibana
111+
ports:
112+
- "5601:5601"
113+
environment:
114+
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
115+
networks:
116+
- microservices-network
117+
depends_on:
118+
- elasticsearch
119+
120+
volumes:
121+
elasticsearch_data:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"dashboard": {
3+
"title": "Microservices Dashboard",
4+
"panels": [
5+
{
6+
"title": "Request Rate",
7+
"type": "graph",
8+
"targets": [
9+
{
10+
"expr": "rate(http_requests_total[5m])",
11+
"legendFormat": "{{service}}"
12+
}
13+
]
14+
},
15+
{
16+
"title": "Response Time",
17+
"type": "graph",
18+
"targets": [
19+
{
20+
"expr": "histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))",
21+
"legendFormat": "95th percentile"
22+
}
23+
]
24+
}
25+
]
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
input {
2+
beats {
3+
port => 5044
4+
}
5+
tcp {
6+
port => 5000
7+
codec => json_lines
8+
}
9+
}
10+
11+
filter {
12+
if [service] {
13+
mutate {
14+
add_field => { "service_name" => "%{service}" }
15+
}
16+
}
17+
18+
if [level] == "ERROR" {
19+
mutate {
20+
add_tag => [ "error" ]
21+
}
22+
}
23+
}
24+
25+
output {
26+
elasticsearch {
27+
hosts => ["elasticsearch:9200"]
28+
index => "microservices-logs-%{+YYYY.MM.dd}"
29+
}
30+
stdout { codec => rubydebug }
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
rule_files:
6+
- "alert_rules.yml"
7+
8+
scrape_configs:
9+
- job_name: 'user-service'
10+
static_configs:
11+
- targets: ['user-service:3001']
12+
metrics_path: '/metrics'
13+
14+
- job_name: 'product-service'
15+
static_configs:
16+
- targets: ['product-service:3002']
17+
metrics_path: '/metrics'
18+
19+
- job_name: 'order-service'
20+
static_configs:
21+
- targets: ['order-service:3003']
22+
metrics_path: '/metrics'
23+
24+
- job_name: 'api-gateway'
25+
static_configs:
26+
- targets: ['api-gateway:3000']
27+
metrics_path: '/metrics'
28+
29+
alerting:
30+
alertmanagers:
31+
- static_configs:
32+
- targets:
33+
- alertmanager:9093
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const promClient = require('prom-client');
2+
3+
// Create metrics
4+
const httpRequestDuration = new promClient.Histogram({
5+
name: 'http_request_duration_seconds',
6+
help: 'Duration of HTTP requests in seconds',
7+
labelNames: ['method', 'route', 'status_code'],
8+
buckets: [0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1.0]
9+
});
10+
11+
const httpRequestsTotal = new promClient.Counter({
12+
name: 'http_requests_total',
13+
help: 'Total number of HTTP requests',
14+
labelNames: ['method', 'route', 'status_code']
15+
});
16+
17+
const performanceMiddleware = (req, res, next) => {
18+
const start = Date.now();
19+
20+
res.on('finish', () => {
21+
const duration = (Date.now() - start) / 1000;
22+
const labels = {
23+
method: req.method,
24+
route: req.route?.path || req.path,
25+
status_code: res.statusCode
26+
};
27+
28+
httpRequestDuration.observe(labels, duration);
29+
httpRequestsTotal.inc(labels);
30+
});
31+
32+
next();
33+
};
34+
35+
module.exports = { performanceMiddleware, httpRequestDuration, httpRequestsTotal };

β€Žshared/security/rateLimiter.jsβ€Ž

Whitespace-only changes.

0 commit comments

Comments
Β (0)