Sub topic 18
Securing and Scaling the Monitoring Stack
This chapter assumes you can edit Linux configuration files, manage systemd services, read YAML, and use basic PromQL. It also assumes Prometheus, node_exporter, Grafana, and Alertmanager are already running in a small environment.
Protect every metrics endpoint
Metrics can reveal hostnames, mount points, kernel details, service names, and resource use. Treat them as operational data, not as public web pages.
Use these controls:
- Keep node_exporter listening on a private network address when possible.
- Allow port
9100only from Prometheus. - Allow Prometheus port
9090only from administrators and Grafana. - Protect Grafana accounts with strong authentication and role-based access.
- Protect Alertmanager because alert messages may contain internal names and incident details.
- Put public access behind a reverse proxy that provides HTTPS and authentication.
- Run exporters as unprivileged users.
- Store credentials in environment variables, a secret manager, or protected files. Do not place passwords in dashboards or source repositories.
A firewall rule is useful, but it is not a replacement for authentication. Network boundaries can fail through routing mistakes or compromised hosts.
Understand the scaling boundary
A single Prometheus server works well for a small fleet. Its local time-series database is fast, but it stores data on the Prometheus host and queries consume its CPU and memory.
| Problem | Usual response | Trade-off |
|---|---|---|
| More targets or labels | Add resources and reduce unnecessary series | Larger servers cost more |
| Longer retention | Use remote storage or a long-term metrics system | More components to operate |
| Multiple locations | Run one Prometheus per location and federate selected data | Queries become more complex |
| Prometheus failure | Run redundant Prometheus servers | Alerts and dashboards may duplicate data |
The largest source of growth is usually cardinality. Cardinality is the number of distinct time series created by metric-label combinations. A label such as instance is useful. A label containing a request ID, user ID, or full URL can create millions of series.
Before adding a label, ask whether you will filter, group, or alert on it. Remove unused collectors and avoid collecting high-cardinality application data without a clear retention plan.
Choose a scaling pattern
For a small deployment, keep Prometheus close to the targets and use Grafana for visualization. When the fleet crosses network or administrative boundaries, place a Prometheus server in each area. A central system can use federation to collect selected recording rules, or remote write to send samples to long-term storage.
Redundant Prometheus servers should use the same rule configuration and alert through Alertmanager, which can group duplicate alerts. Test failure behavior instead of assuming redundancy works.
Plan retention and recovery
Choose retention from incident needs. A short local retention period may be enough for troubleshooting, while long-term capacity planning needs durable remote storage. Monitor Prometheus itself with metrics such as disk usage, scrape failures, rule evaluation duration, and sample ingestion rate.
Back up configuration, rule files, dashboards, Alertmanager routes, and Grafana data. Metric data is often less important to restore than the configuration that explains and alerts on it.
Exercise
A new label causes Prometheus disk usage to grow rapidly. What should you inspect first?
Show answer
Inspect the label's cardinality and remove or redesign values that create a distinct series for each request, user, or URL.