【问题标题】:Is any way to store Prometheus Data to External Database like mysql or postgreSQL有什么方法可以将 Prometheus 数据存储到外部数据库,如 mysql 或 postgreSQL
【发布时间】:2018-07-16 13:49:30
【问题描述】:

目前我正在使用 Prometheus 并取得了不错的结果,我面临的困难是如果服务重新启动,我的整个旧数据都会丢失。有没有办法将 Prometheus 数据永久存储在 mysql 或 PostgreSQL 等数据库中?

【问题讨论】:

    标签: mysql database postgresql prometheus prometheus-operator


    【解决方案1】:

    您不能将 Prometheus 数据直接写入关系数据库(或任何数据库)。你有两个选择:

    1. 在您的计算机上安装一个外部磁盘并配置 Prometheus 以将数据写入该安装位置的任何位置
    2. 编写一个小型 Web 脚本,将 Prometheus 导出格式转换为您想要的任何存储格式。然后配置 Prometheus 将数据发送到 Web 脚本。

    可以在Prometheus docs上找到信息。

    【讨论】:

    【解决方案2】:

    传统数据库(如 MySQL 和 PostgreSQL)并未针对 Prometheus 收集的时间序列数据进行优化。存在更好的解决方案,它们需要更少的存储空间,并且在插入和选择方面工作得更快。

    Prometheus 支持remote storage。启用后,它将所有新数据存储在本地存储和远程存储中。远程存储数据库有多种选择,需要权衡取舍。我建议尝试VictoriaMetrics。它原生支持 Prometheus 的查询语言 PromQL,因此可以很容易地用作 Grafana 中的 Prometheus 数据源。

    【讨论】:

    • 一个好消息是,现在我们可以使用以下github.com/timescale/pg_Prometheus 将 Prometheus 数据存储到 PostgreSQL,并且可以将 timescale-db 与 PostgreSQL 一起用作其他介质
    【解决方案3】:

    这里现在 PostgreSQL 支持 Prometheus

    https://blog.timescale.com/prometheus-ha-postgresql-8de68d19b6f5

    【讨论】:

      【解决方案4】:

      InfluxDB 将是另一种选择:

      https://www.influxdata.com/blog/influxdb-now-supports-prometheus-remote-read-write-natively/

      只需在 Prometheus 配置中配置 remote_write 和 remote_read 即可:

      remote_write:
        - url: 'http://{YOUR_INFLUX-DB}:{YOUR_INFLUX-DB_PORT}/api/v1/prom/write?db=metrics'
      remote_read:
        - url: 'http://{YOUR_INFLUX-DB}:{YOUR_INFLUX-DB_PORT}/api/v1/prom/read?db=metrics'
      

      【讨论】:

        猜你喜欢
        • 2019-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-14
        • 1970-01-01
        • 2021-12-11
        • 2012-01-22
        相关资源
        最近更新 更多