Prometheus Storage: Mastering Local Time Series Data
Prometheus's local storage is designed to efficiently manage time series data, addressing the need for reliable and fast access to metrics. By storing data in a highly efficient custom format, it ensures that you can ingest and query metrics without significant overhead. This is especially important in environments where performance and reliability are paramount, such as monitoring critical systems.
The storage mechanism works by grouping ingested samples into two-hour blocks. Each block contains a directory with a 'chunks' subdirectory for time series samples, a metadata file, and an index file that maps metric names and labels to the corresponding time series. The write-ahead log (WAL) secures incoming samples against crashes, allowing for a replay of data upon server restarts. You can configure storage parameters like the retention time with --storage.tsdb.retention.time, which defaults to 15 days, and the storage path with --storage.tsdb.path, defaulting to data/. Be mindful of the fact that non-POSIX compliant filesystems are not supported, as they can lead to unrecoverable corruptions.
In production, understanding the implications of these configurations is vital. For example, calculating needed disk space can be done using the formula: needed_disk_space = retention_time_seconds * ingested_samples_per_second * bytes_per_sample. Ensure you are using a local filesystem to avoid issues with NFS, which is not recommended. Additionally, the WAL compression feature, enabled by default since version 2.20.0, can help reduce disk usage without sacrificing performance.
Key takeaways
- →Understand the storage structure: Prometheus organizes data into two-hour blocks with chunks and index files.
- →Configure retention settings: Use `--storage.tsdb.retention.time` to manage how long data is kept.
- →Avoid non-POSIX filesystems: Stick to local filesystems to prevent data corruption issues.
- →Calculate disk space requirements: Use the formula for estimating needed disk space based on retention and ingestion rates.
- →Leverage WAL compression: Enable WAL compression to optimize disk usage without impacting performance.
Why it matters
Efficient storage management in Prometheus directly impacts the reliability and performance of your monitoring setup. Proper configurations ensure that you can handle large volumes of metrics without data loss or corruption.
Code examples
1./data
2 01BKGV7JBM69T2G1BGBGM6KB12
3 meta.json
4 01BKGTZQ1SYQJTR4PB43C8PD98
5 chunks
6 000001
7 tombstones
8 index
9 meta.json
10 01BKGTZQ1HHWHV8FBJXW1Y3W0K
11 meta.json
12 01BKGV7JC0RY8A6MACW02A2PJD
13 chunks
14 000001
15 tombstones
16 index
17 meta.json
18 chunks_head
19 000001
20 wal
21 000000002
22 checkpoint.00000001
23 00000000needed_disk_space = retention_time_seconds * ingested_samples_per_second * bytes_per_samplepromtool will write the blocks to a directory. By default this output directory is ./data/, you can change it by using the name of the desired output directory as an optiWhen NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsUnified observability — logs, uptime monitoring, and on-call in one place. Used by 50,000+ engineering teams to ship faster and sleep better.
Try Better Stack free →Mastering Linux Host Metrics with Prometheus Node Exporter
Unlock the full potential of your Linux infrastructure by monitoring host metrics with the Prometheus Node Exporter. This tool exposes critical hardware and kernel metrics, making it easier to keep your systems healthy. Learn how to set it up and what to watch out for in production.
Mastering Recording Rules in Prometheus: Boost Your Observability
Recording rules are crucial for optimizing your Prometheus setup by precomputing expensive queries. Learn how to define them effectively to enhance your observability stack. This article dives into practical configurations and common pitfalls.
Mastering Histograms and Summaries in Prometheus
Unlock the power of observability with Prometheus histograms and summaries. Learn how these metric types can provide deep insights into your application's performance through bucketed observations and pre-configured quantiles.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.