Prometheus, a powerful open-source monitoring system, collects and stores time-series data for analysis and alerting. However, its default storage retention period may not suffice for long-term trend analysis or compliance requirements. This guide will walk you through the process of increasing Prometheus storage retention, enabling you to harness the full potential of your monitoring data.

Understanding Prometheus Storage Retention

Prometheus storage retention refers to the duration for which time-series data is kept before being automatically purged. By default, Prometheus retains data for 15 days — a period that may prove insufficient for many use cases. Storage retention is influenced by factors such as data volume, storage capacity, and the specific needs of your monitoring environment.

Why Increase Prometheus Storage Retention?

Extending Prometheus storage retention offers several benefits:

  1. Long-term trend analysis: Access historical data for capacity planning and identifying gradual performance shifts.
  2. Compliance and auditing: Meet regulatory requirements that mandate extended data retention periods.
  3. Enhanced debugging: Investigate issues by examining historical data patterns over longer timeframes.
  4. Improved decision-making: Make informed choices based on comprehensive, long-term data insights.

How to Check Current Prometheus Retention Settings

Before modifying retention settings, it's crucial to verify the current configuration:

  1. Locate the Prometheus configuration file (usually prometheus.yml).
  2. Look for the -storage.tsdb.retention.time flag in the startup command or configuration.
  3. Access the Prometheus UI and navigate to the /config endpoint to view current settings.
  4. Use the Prometheus API to query retention information:
curl -s http://localhost:9090/api/v1/status/runtimeinfo | jq '.data.storageRetention'

Step-by-Step Guide to Increase Prometheus Storage Retention

Follow these steps to extend Prometheus storage retention:

  1. Open the ****Prometheus service file. It is usually located at /etc/systemd/system/prometheus.service.
vi /etc/systemd/system/prometheus.service
  1. Locate or add the -storage.tsdb.retention.time flag.
  2. Set the desired retention period (e.g., 30d for 30 days, 720h for 30 days, or 1y for 1 year).
  3. Save the changes and restart Prometheus to apply the new settings.

Example configuration:

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/usr/local/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries
    --storage.tsdb.retention.time=60d
[Install]
WantedBy=default.target

If you have Prometheus installed on macOS using Homebrew:

  1. Confirm the location of your prometheus.yml file. It is usually located at /opt/homebrew/etc/prometheus.yml.
ls /opt/homebrew/etc/prometheus.yml
  1. When starting Prometheus, explicitly state the location of the configuration file and pass in the --storage.tsdb.retention.time flag. Set this to your desired retention period.

Example configuration:

/opt/homebrew/opt/prometheus/bin/prometheus --config.file=/opt/homebrew/etc/prometheus.yml --storage.tsdb.retention.time=30d

Increasing Retention for Dockerized Prometheus

For containerized Prometheus deployments:

  1. Modify the Docker run command or docker-compose file.
  2. Add or update the -storage.tsdb.retention.time flag in the command arguments.
  3. Ensure persistent storage is configured to retain data across container restarts.

Example docker-compose.yml snippet:

services:
  prometheus:
    image: prom/prometheus:v2.37.0
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention.time=30d'
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus

Best Practices for Managing Increased Retention

Implementing extended retention requires careful consideration:

  • Estimate storage requirements: Calculate the expected data growth to ensure sufficient disk space.
  • Implement data compression: Enable TSDB compression to reduce storage consumption.
  • Utilize remote storage: Consider using remote storage solutions for long-term data retention.
  • Monitor system performance: Regularly check query performance and resource utilization after increasing retention.

Troubleshooting Common Issues

When increasing Prometheus storage retention, you may encounter:

  1. Insufficient disk space: Address by adding storage or implementing data compression.
  2. Data inconsistencies: Verify data integrity and consider restarting Prometheus with a clean storage directory.
  3. Increased query latency: Optimize queries and consider implementing recording rules for frequently accessed metrics.
  4. Startup failures: Check logs for retention-related errors and ensure proper configuration syntax.

Key Takeaways

  • Increasing Prometheus retention enhances long-term data analysis capabilities.
  • Proper configuration of the retention flag is crucial for effective implementation.
  • Consider storage capacity and system performance when extending retention periods.
  • Regular monitoring and optimization are essential for managing increased data volumes.

FAQs

What is the default retention period for Prometheus?

The default retention period is 15 days.

Can I change retention settings without restarting Prometheus?

No, changes to retention settings require a Prometheus restart to take effect.

How does increasing retention affect Prometheus performance?

Extended retention may impact query performance and increase storage requirements. Monitor system resources and optimize as needed.

Is there a maximum limit to Prometheus retention time?

There's no hard limit, but practical constraints like storage capacity and query performance should be considered when setting retention periods.

Enhance Your Monitoring with SigNoz

While Prometheus offers powerful monitoring capabilities, managing retention and scaling can become challenging as your infrastructure grows. SigNoz provides a comprehensive monitoring solution that builds upon Prometheus' strengths while addressing its limitations.

SigNoz cloud is the easiest way to run SigNoz. Sign up for a free account and get 30 days of unlimited access to all features. Try SigNoz Cloud
CTA You can also install and self-host SigNoz yourself since it is open-source. With 18,000+ GitHub stars, open-source SigNoz is loved by developers. Find the instructions to self-host SigNoz.

With SigNoz, you can:

  • Easily manage long-term data retention without complex configuration
  • Scale your monitoring infrastructure effortlessly
  • Access advanced querying and visualization capabilities
  • Benefit from integrated tracing and logging alongside metrics

By leveraging SigNoz, you can focus on deriving insights from your monitoring data rather than managing the underlying infrastructure. Whether you choose the cloud offering or the open-source version, SigNoz empowers you to take your monitoring to the next level.

Was this page helpful?