【问题标题】:Increasing Prometheus storage retention增加 Prometheus 存储保留
【发布时间】:2020-04-05 12:05:44
【问题描述】:

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

【问题讨论】:

  • Prometheus 支持将数据复制到long-term storage systems 的 remote_write 机制,因此以后可以从这些系统中查询数据。最有前途的系统是 Cortex、m3db 和VictoriaMetrics

标签: monitoring prometheus


【解决方案1】:
  1. 编辑 prometheus.service 文件

vi /etc/systemd/system/prometheus.service

  1. 将下面的"--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

【讨论】:

    【解决方案2】:

    您可以在启动 Prometheus 时设置 --storage.tsdb.retention.time 标志。它定义了数据在时间序列数据库 (TSDB) 中的保存时间。默认值为 15 天。

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

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

    请参阅Prometheus documentation

    【讨论】:

    • 这个可以在yml中设置吗?
    • 不,只能使用命令行标志设置。这是immutable system parameter
    • 请注意这个答案,“m”代表“分钟”而不是“月”,如下所述:manpages.debian.org/unstable/prometheus/prometheus.1.en.html
    • 要为这个答案添加一些上下文,默认为 15 天是有原因的。根据docsPrometheus 的本地存储并不意味着持久的长期存储。如果一年的指标对运营至关重要,请确保您的存储适当地配置了持久性。
    【解决方案3】:

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

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

    谢谢 普拉桑特

    【讨论】:

      【解决方案4】:

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

      /etc/default/prometheus
      

      像这样:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-28
        • 2021-04-03
        • 2020-03-02
        • 2021-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多