Configuring Prometheus data retention

You can control how long Prometheus stores monitoring data and how much disk space it consumes by configuring retention settings in the Prometheus service specification. Prometheus is the component responsible for storing metrics; therefore, retention policies must be applied to the Prometheus spec.

Before you begin

Before you begin, make sure that you have the following prerequisites in place:
  • Prometheus is deployed and managed by Cephadm.
  • You have cluster administrator privileges.
  • Prometheus is running.
    ceph orch ls | grep prometheus

Procedure

  1. Create or edit the prometheus.yaml specification file.
    service_type: prometheus
    service_name: prometheus
    placement:
      count: 1
    spec:
      retention_time: "30d"     # Retain data for 30 days
      retention_size: "50GB"    # Limit storage to 50 GB
     
  2. Review the parameter descriptions:
    retention_time
    Defines how long Prometheus retains monitoring data. Supported units: y, w, d, h, m, s. The default value is 15 days.
    retention_size
    Defines the maximum size of Prometheus time-series database (TSDB). Supported units: B, KB, MB, GB, TB, PB, EB. The default value is 0 (disabled)
  3. Apply the updated specification file.
    ceph orch apply -i prometheus.yaml
  4. Redeploy Prometheus to activate changes.
    ceph orch redeploy prometheus
  5. Verify that the retention configuration is active:
    ceph orch ps | grep prometheus

Example

Example

The following example configures Prometheus to retain monitoring data for one year or up to 100 GB.

service_type: prometheus
service_name: prometheus
placement:
  count: 1
spec:
  retention_time: "1y"
  retention_size: "100GB"
 

Prometheus automatically deletes older data when either the time-based or size-based threshold is reached.

Prometheus now enforces the configured retention policy. If Prometheus was already deployed before applying the updated specification, redeployment ensures that the new settings take effect.