增加 Prometheus 存储保留

Roh*_*ati 19 monitoring prometheus

您好,我的 AWS 实例上安装了 Prometheus 服务器,但数据在 15 天后自动删除。我需要一年或几个月的数据,我的 prometheus 配置有什么需要改变的吗?或者我是否需要像 Thanos 这样的扩展程序,我是 Prometheus 的新手,所以请轻松回答

Pra*_*bhu 17

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

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

因此,配置将如下所示,保留 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
Run Code Online (Sandbox Code Playgroud)


wei*_*eld 15

还有的--storage.tsdb.retention.time标志,当你开始普罗米修斯你可以设置。它定义了数据在时间序列数据库 (TSDB) 中的保存时间。默认值为 15 天。

因此,要将保留时间增加到一年,您应该能够将其设置为:

--storage.tsdb.retention.time=1y
# or
--storage.tsdb.retention.time=365d
Run Code Online (Sandbox Code Playgroud)

请参阅Prometheus 文档

  • 请小心这个答案,“m”代表“分钟”而不是“月”,如下所述:https://manpages.debian.org/unstable/prometheus/prometheus.1.en.html (7认同)
  • 可以在yml中设置吗? (5认同)
  • 为了给这个答案添加一些背景信息,默认为 15 天是有原因的。根据 [docs](https://prometheus.io/docs/prometheus/latest/storage/#operational-aspects),_Prometheus 的本地存储并不意味着持久的长期存储。_确保您的存储经过适当配置,具有持久性一年的指标是否对运营至关重要。 (2认同)

小智 11

在部署 yml 文件中添加以下内容允许我更改存储保留天数

image: 'your/image path' 
args:
  - '--storage.tsdb.path=/prometheus'
  - '--storage.tsdb.retention.time=45d'
  - '--config.file=/etc/prometheus/prometheus.yml'
Run Code Online (Sandbox Code Playgroud)

  • 这可能应该说明 Docker 安装已被假定。 (4认同)

rbs*_*rbs 8

在 Debian 上,您不必编辑 systemd-config。您只需将参数添加到

/etc/default/prometheus
Run Code Online (Sandbox Code Playgroud)

像这样:

# Set the command-line arguments to pass to the server.
ARGS="--storage.tsdb.retention.time=60d"
Run Code Online (Sandbox Code Playgroud)