简体   繁体   中英

Increasing Prometheus storage retention

Hi I have Prometheus server installed on my AWS instance but the data is been removed automatically after 15 days. I need to have data for an year or months, is there anything I need to change in my prometheus configuration? Or do I need any extensions like Thanos, I am new to Prometheus so please be easy on the answers

  1. Edit the prometheus.service file vi /etc/systemd/system/prometheus.service

  2. add "--storage.tsdb.retention.time=1y" below to "ExecStart=/usr/local/bin/prometheus ".

So the config will look like bellow for 1 year of data retention.

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
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 \
    --web.external-url=http://34.89.26.156:9090 \
    --storage.tsdb.retention.time=1y
[Install]
WantedBy=multi-user.target

There's the --storage.tsdb.retention.time flag that you can set when you start Prometheus. It defines how long data is kept in the time-series database (TSDB). The default is 15 days.

So, to increase the retention time to a year, you should be able to set this to something like:

--storage.tsdb.retention.time=1y
# or
--storage.tsdb.retention.time=365d

See the Prometheus documentation .

adding below in deployment yml file allowed me change storage retention days

image: 'your/image path' 
args:
  - '--storage.tsdb.path=/prometheus'
  - '--storage.tsdb.retention.time=45d'
  - '--config.file=/etc/prometheus/prometheus.yml'

Thanks Prashanth

On Debian you do not have to edit the systemd-config. You simply can add the arguments to

/etc/default/prometheus

like so:

# Set the command-line arguments to pass to the server.
ARGS="--storage.tsdb.retention.time=60d"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM