The Monitoring Engineer builds observability systems that let teams detect, diagnose, and resolve production incidents quickly. The three pillars - metrics, logs, traces - each answer different questions: metrics detect that something is wrong, logs explain why, and traces show where in a distributed system the failure originates.
SLO Definition
# SLO (Service Level Objective) - measurable target for reliability
# Error budget = 1 - SLO. A 99.9% SLO gives 8.7h/year error budget.
Service: Payment API
SLIs (Service Level Indicators - what we measure):
- Availability: successful responses / total requests
- Latency: % of requests served in < 500ms
SLOs (targets):
- Availability: 99.9% over 30-day rolling window
- Latency: 95% of requests < 500ms, 99% < 2000ms
Error budget (for 99.9%):
- 43.2 min/month of allowed downtime
- Policy: if < 50% error budget remains, freeze non-critical deployments
Prometheus Metrics (Node.js)
import { Registry, Counter, Histogram } from 'prom-client';
const registry = new Registry();
const httpRequestsTotal = new Counter({
name: 'http_requests_total',
help: 'Total HTTP requests',
labelNames: ['method', 'route', 'status_code'],
registers: [registry],
});
const httpRequestDuration = new Histogram({
name: 'http_request_duration_seconds',
help: 'HTTP request duration',
labelNames: ['method', 'route'],
buckets: [0.01, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5],
registers: [registry],
});
// Middleware
app.use((req, res, next) => {
const end = httpRequestDuration.startTimer({ method: req.method, route: req.path });
res.on('finish', () => {
httpRequestsTotal.inc({ method: req.method, route: req.path, status_code: res.statusCode });
end();
});
next();
});
// Metrics endpoint for Prometheus scraping
app.get('/metrics', async (req, res) => {
res.set('Content-Type', registry.contentType);
res.send(await registry.metrics());
});
Alerting Rules (Prometheus)
# alerts.yml
groups:
- name: api_alerts
rules:
# Alert when error rate > 1% for 5 minutes
- alert: HighErrorRate
expr: |
rate(http_requests_total{status_code=~"5.."}[5m])
/ rate(http_requests_total[5m]) > 0.01
for: 5m
labels: { severity: critical }
annotations:
summary: "High error rate: {{ $value | humanizePercentage }}"
runbook: "https://wiki.example.com/runbooks/high-error-rate"
# Alert when p99 latency > 2s
- alert: SlowResponses
expr: |
histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 2
for: 5m
labels: { severity: warning }
annotations:
summary: "p99 latency {{ $value }}s exceeds 2s threshold"