我在 AWS 实例上安装了 Prometheus 服务器,但数据在 15 天后自动删除。我需要一年或几个月的数据。我的普罗米修斯配置有什么需要更改的吗?
或者我需要像 Thanos 这样的扩展吗?我是普罗米修斯的新手,所以请简单地回答。
vi /etc/systemd/system/prometheus.service
"--storage.tsdb.retention.time=1y"
添加到 "ExecStart=/usr/local/bin/prometheus \"
行。因此,对于 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
启动 Prometheus 时可以设置
--storage.tsdb.retention.time
标志。它定义了数据在时间序列数据库(TSDB)中保存的时间。默认为 15 天。
因此,要将保留时间增加到一年,您应该能够将其设置为:
--storage.tsdb.retention.time=1y
# or
--storage.tsdb.retention.time=365d
请参阅 Prometheus 文档。
在部署 yml 文件中添加以下内容允许我更改存储保留天数
image: 'your/image path'
args:
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=45d'
- '--config.file=/etc/prometheus/prometheus.yml'
在 Debian 上,您不必编辑 systemd-config。您只需将参数添加到
/etc/default/prometheus
像这样:
# Set the command-line arguments to pass to the server.
ARGS="--storage.tsdb.retention.time=60d"
在通过 snap 安装了 prometheus 的 Ubuntu 上,编辑
/var/snap/prometheus/current/daemon_arguments
并将 --storage.tsdb.retention.time=1y
添加到顶部的 ARGS=
行。
重新启动普罗米修斯快照:
systemctl restart snap.prometheus.prometheus.service