Increasing Prometheus Storage Retention

Better Stack Team
Updated on December 2, 2024

Increasing the storage retention period for Prometheus allows you to keep your metrics data for a longer duration, which can be essential for historical analysis, debugging, and reporting. Here's how you can configure Prometheus to extend its storage retention period.

Step 1: Update Prometheus Configuration

Prometheus allows you to configure the retention time via command-line flags when you start the Prometheus server. The primary flag for setting the retention duration is --storage.tsdb.retention.time.

Example Configuration

If you're running Prometheus via a command line or as a service, you can set the retention period like this:

 
./prometheus --config.file=prometheus.yml --storage.tsdb.retention.time=30d

In this example, the retention period is set to 30 days. You can specify different durations using the following time units:

  • s for seconds
  • m for minutes
  • h for hours
  • d for days
  • w for weeks

For example:

  • 7d for 7 days
  • 1w for 1 week
  • 12h for 12 hours

Step 2: Persistent Storage Considerations

When increasing the retention period, you must also consider the storage capacity of your Prometheus instance. Longer retention periods mean more disk space will be used. To manage storage effectively, you can do the following:

  1. Use External Storage: If you need to retain data for an extended period, consider using remote storage solutions compatible with Prometheus, such as Thanos, Cortex, or InfluxDB.
  2. Monitor Disk Usage: Regularly check your disk usage to ensure that you do not run out of space. You can use tools like Grafana to visualize disk usage metrics.
  3. Optimize Metrics: Reduce the amount of data being collected by filtering out unnecessary metrics or labels. This can help save space.

Step 3: Restart Prometheus

After making changes to the command line flags, restart your Prometheus server to apply the new retention settings. If you're running Prometheus as a service, the command may look like this:

 
sudo systemctl restart prometheus

Step 4: Verify Retention Settings

Once Prometheus is restarted, you can verify the configured retention time by checking the Prometheus logs. Look for a line that indicates the retention settings, such as:

 
level=info ts=2024-10-25T12:00:00.000Z caller=main.go:705 msg="Server is ready to receive requests."
level=info ts=2024-10-25T12:00:00.000Z caller=main.go:740 msg="Storage retention set to 30d"

You can also check the web UI for metrics that indicate the retention policy.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github