简体   繁体   English

增加 Prometheus 存储保留

[英]Increasing Prometheus storage retention

Hi I have Prometheus server installed on my AWS instance but the data is been removed automatically after 15 days.您好,我的 AWS 实例上安装了 Prometheus 服务器,但数据在 15 天后自动删除。 I need to have data for an year or months, is there anything I need to change in my prometheus configuration?我需要一年或几个月的数据,我的 prometheus 配置有什么需要改变的吗? Or do I need any extensions like Thanos, I am new to Prometheus so please be easy on the answers或者我是否需要像 Thanos 这样的扩展程序,我是 Prometheus 的新手,所以请轻松回答

  1. Edit the prometheus.service file vi /etc/systemd/system/prometheus.service编辑 prometheus.service 文件 vi /etc/systemd/system/prometheus.service

  2. add "--storage.tsdb.retention.time=1y" below to "ExecStart=/usr/local/bin/prometheus ".在“ExecStart=/usr/local/bin/prometheus”下面添加“--storage.tsdb.retention.time=1y”。

So the config will look like bellow for 1 year of data retention.因此,配置将如下所示,保留 1 年的数据。

[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.您可以在启动 Prometheus 时设置--storage.tsdb.retention.time标志。 It defines how long data is kept in the time-series database (TSDB).它定义了数据在时间序列数据库 (TSDB) 中的保存时间。 The default is 15 days.默认值为 15 天。

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 .请参阅Prometheus 文档

adding below in deployment yml file allowed me change storage retention days在部署 yml 文件中添加以下内容允许我更改存储保留天数

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.在 Debian 上,您不必编辑 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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