configurationprometheusstorage

How to configure prometheus storage options


I have installed Prometheus in a vim using apt install prometheus. I want to configure storage location and retention size. Here is the excerpt from the documentation

Prometheus has several flags that configure local storage. The most important are:

--storage.tsdb.path: Where Prometheus writes its database. Defaults to data/.
--storage.tsdb.retention.time: How long to retain samples in storage. If neither this flag nor storage.tsdb.retention.size is set, the retention time defaults to 15d. Supported units: y, w, d, h, m, s, ms.
--storage.tsdb.retention.size: The maximum number of bytes of storage blocks to retain

I have tried editing the prometheus.yml file and I keep getting an error "unable to unmarshall". Here is what I have tried.

global:
  storage:
    tsdb:
      path: "/data/prometheus"
      retention:
        time: "30d"
        size: "50GB"

I have also tried out side of the global directive. I can't figure out how to configure the storage. Is this the right place to configure this? Or do I edit the systemd file and add them as arguments?

Thanks


Solution

  • I have tried editing the prometheus.yml file and I keep getting an error "unable to unmarshall".
    Or do I edit the systemd file and add them as arguments?

    Prometheus manages configuration in two ways:

    To configure Prometheus storage options, which is immutable, you can pass the configuration via command line when starting prometheus:

    ./prometheus --storage.tsdb.path=/data/prometheus --storage.tsdb.retention.time=30d --storage.tsdb.retention.size=50GB
    

    If you are running Prometheus via systemd, simply alter the ExecStart command in prometheus.service file to something like the following:

    ....
    [Service]
    User=prometheus
    Group=prometheus
    Restart=on-failure
    ExecStart=/opt/prometheus/prometheus \
      --storage.tsdb.path=/data/prometheus \
      --storage.tsdb.retention.time=30d \
      --storage.tsdb.retention.size=50GB
    ...
    
    

    Here is the list of all configuration that are immutable, and need to be configure via command line.