InfluxDB and Telegraf: Millions of Metrics Without Filling the Disk
Monday morning, and the disk-usage alert hits 95% on the monitoring server. It isn’t a business app or a customer database: it’s the system that was supposed to warn you about problems, and its own data has left it without space. It’s a familiar story. You start collecting CPU and memory every 10 seconds on ten machines, add a hundred servers, turn on more plugins, and six months later you’re sitting on hundreds of millions of points nobody planned for.
The good news is that InfluxDB and Telegraf make one of the most efficient pairings for collecting and storing server metrics at scale, provided you configure them thoughtfully. This article covers how to size your setup, what to tune on the agent, how to design retention, and how to avoid the number-one cause of trouble: runaway cardinality.
Why InfluxDB and Telegraf Work Well Together
Telegraf is a lightweight Go agent with hundreds of input plugins (CPU, disk, network, Docker, PostgreSQL, Nginx, SNMP…) and outputs. InfluxDB is a time series database optimized for massive writes and time-range queries. Both are InfluxData projects, which means the write protocol (line protocol) and conventions fit together seamlessly.
Unlike a scraping model like Prometheus, here the agent pushes the data. That brings clear advantages:
- It works well with servers behind NAT or on segregated networks, with no inbound ports to open.
- Telegraf buffers in memory if the InfluxDB server stops responding, so brief outages don’t leave gaps.
- A single agent covers system, application and network-device metrics.
If you need PromQL-based alerting and service discovery, it’s worth comparing approaches; we cover that in Prometheus and Grafana: Critical Alerts to Slack and Telegram. But for infrastructure telemetry with tiered retention, the Influx combo remains a very solid choice.
Size It Before You Install: The Math Almost Nobody Does
Disk space doesn’t run out by accident. You can estimate it. Picture this scenario:
- 500 servers.
- 150 series per server (CPU per core, disks, interfaces, processes, memory).
- A 10-second interval.
That’s 75,000 series and roughly 7,500 points per second, around 648 million points a day. With the TSM engine’s compression, a numeric point typically takes 2 to 4 bytes on disk, so we’re talking about 1.3 to 2.6 GB per day, order of magnitude. That sounds manageable, but with no retention policy you’ll pile up almost a terabyte of high-resolution data a year that almost nobody queries.
The practical takeaway: the problem isn’t writes, it’s the resolution you keep and for how long. That decision belongs in the design phase, not the moment the disk is full.
Basic Docker Install
For a test environment or a dedicated server, Docker makes startup easy. Here’s a minimal docker-compose.yml:
services:
influxdb:
image: influxdb:2.7
restart: unless-stopped
ports:
- "8086:8086"
volumes:
- influx-data:/var/lib/influxdb2
- influx-config:/etc/influxdb2
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: admin
DOCKER_INFLUXDB_INIT_PASSWORD_FILE: /run/secrets/influx_pass
DOCKER_INFLUXDB_INIT_ORG: miempresa
DOCKER_INFLUXDB_INIT_BUCKET: metrics_raw
DOCKER_INFLUXDB_INIT_RETENTION: 14d
volumes:
influx-data:
influx-config:
Note two details. First, the initial bucket is created with 14-day retention, so you avoid infinite growth by default. Second, the password is passed via a file rather than as plain text; to take that discipline further, see secret management with OpenBao and keep Telegraf tokens out of your repositories.
Put the data volume on a dedicated disk or volume, ideally SSD/NVMe. InfluxDB does a lot of sequential writes and compactions, and sharing a disk with the OS is a recipe for latency spikes.
Telegraf: Collect Less to Store Better
The classic mistake is leaving Telegraf on its default config and enabling every plugin you can find. Every metric you collect is a permanent cost. Start with the agent block:
[agent]
interval = "30s"
round_interval = true
collection_jitter = "5s"
metric_batch_size = 5000
metric_buffer_limit = 100000
flush_interval = "15s"
flush_jitter = "5s"
omit_hostname = false
An Interval That Makes Sense
Going from 10 to 30 seconds cuts volume to a third. For CPU and memory on general-purpose servers, 30 seconds is usually plenty. Save 10 seconds (or less) for critical services by setting a per-plugin interval.
Jitter and Batch to Avoid Storms
With hundreds of synchronized agents, they’d all write in the same second. collection_jitter and flush_jitter spread the load and smooth the peaks in InfluxDB. A metric_batch_size of several thousand reduces the number of HTTP requests, and metric_buffer_limit defines how much the agent can hold if the server goes down.
Filter at the Source
Disk plugins are a good example of noise:
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.cpu]]
percpu = false
totalcpu = true
collect_cpu_time = false
report_active = true
[[inputs.net]]
interfaces = ["eth*", "ens*", "bond*"]
Turning off percpu on 64-core machines removes dozens of series per server. Excluding overlay on hosts with many containers keeps every temporary mount from creating a new series. And if a plugin emits fields you’ll never use, drop them with fielddrop or fieldpass inside the plugin’s own section.
Cardinality: The Real Enemy of Performance
More than the number of points, what chokes InfluxDB is the number of unique series: combinations of measurement, tags and tag values. If you put a continuously changing value in a tag (request ID, ephemeral pod name, process PID, URL with parameters), every value creates a new series. The index grows, memory spikes, and queries crawl.
Simple rules to keep it under control:
- Tags for bounded dimensions: host, environment, region, role, datacenter. Values you can enumerate.
- Fields for freely varying values: numbers, counters, states.
- No unique identifiers in tags.
- Review process and container plugins, the most likely to explode cardinality.
You can watch it with the Flux query influxdb.cardinality() over a bucket and range, or with InfluxDB’s own internal metrics. Make that review a recurring task, just like checking certificates.
Telegraf can help with processors too. With processors.regex or processors.override you can normalize tags before sending them, for example grouping pod names like api-7d9f8c-xk2lp under api.
Retention and Downsampling: The Key to Keeping the Disk in Check
Here’s the heart of the strategy. Instead of keeping everything at maximum resolution forever, use a tiered architecture:
| Bucket | Resolution | Retention | Use |
|---|---|---|---|
metrics_raw | 30 s | 14 days | Recent diagnosis |
metrics_5m | 5 min | 90 days | Weekly analysis |
metrics_1h | 1 hour | 2 years | Trends and capacity |
Create the buckets from the CLI:
influx bucket create -n metrics_5m -o miempresa -r 90d
influx bucket create -n metrics_1h -o miempresa -r 730d
And automate the rollup with an InfluxDB task in Flux:
option task = {name: "downsample_5m", every: 5m}
from(bucket: "metrics_raw")
|> range(start: -10m)
|> filter(fn: (r) => r._measurement == "cpu" or r._measurement == "mem")
|> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
|> to(bucket: "metrics_5m", org: "miempresa")
With this scheme, the bulk of the volume lives for only two weeks. The 5-minute data takes up a tiny fraction, and the 1-hour data is practically anecdotal. It’s the difference between a disk that grows forever and one whose usage levels off at a predictable plateau.
One important caveat: use mean for gauges like CPU, but max for peaks and last for cumulative counters. Averaging a network-bytes counter will give you meaningless numbers.
Security and Day-to-Day Operations
A metrics server exposes valuable information about your infrastructure. Cover the basics:
- TLS in front of InfluxDB, whether via a reverse proxy or your own certificates.
- Least-privilege tokens: a write-only token per environment, scoped to the
metrics_rawbucket. - Reproducible Telegraf deployment: manage the agent and its config with Ansible so every new server is born monitored. If you already automate fleet security, it fits naturally with Ansible for Linux server hardening.
- Monitor the monitor: enable Telegraf’s
inputs.internalplugin to watch dropped metrics, write errors and buffer size.
And don’t forget backups: influx backup produces consistent snapshots you can ship to external storage.
Visualization: From Millions of Points to Decisions
Storing well only pays off if you query well. Connect InfluxDB as a data source in Grafana and point your panels at the right bucket for each time range: metrics_raw for the last few hours, metrics_5m for weeks and metrics_1h for months. That keeps queries fast and stops you from scanning millions of points to draw a yearly chart.
To structure your panels thoughtfully, from server health to business indicators, our guide on Grafana dashboards for business and infrastructure will help.
Final Production Checklist
Before you call the deployment done, go through these points:
- Raw bucket with short retention (7–30 days).
- Aggregated buckets with active downsampling tasks.
- Collection interval tuned by criticality.
ignore_fs,fieldpassand filters applied to noisy plugins.- Cardinality reviewed after every new integration.
- Jitter configured and batch size matched to volume.
- Data volume on fast, dedicated disk.
- Alerts on disk usage and Telegraf’s internal metrics.
Conclusion
Collecting millions of metrics doesn’t require massive infrastructure, just discipline: measure with intent, keep cardinality in check, and accept that not all data deserves to live forever at maximum resolution. InfluxDB and Telegraf give you the tools, but retention design and source-side filtering are what separate a stable system from one that wakes you up at dawn because a disk is full.
Start with a sizing calculation, tune the agent, create your tiered buckets and automate downsampling. In an afternoon you can go from a fragile monitor to a metrics platform that scales with you.