【发布时间】:2018-07-16 13:49:30
【问题描述】:
目前我正在使用 Prometheus 并取得了不错的结果,我面临的困难是如果服务重新启动,我的整个旧数据都会丢失。有没有办法将 Prometheus 数据永久存储在 mysql 或 PostgreSQL 等数据库中?
【问题讨论】:
标签: mysql database postgresql prometheus prometheus-operator
目前我正在使用 Prometheus 并取得了不错的结果,我面临的困难是如果服务重新启动,我的整个旧数据都会丢失。有没有办法将 Prometheus 数据永久存储在 mysql 或 PostgreSQL 等数据库中?
【问题讨论】:
标签: mysql database postgresql prometheus prometheus-operator
您不能将 Prometheus 数据直接写入关系数据库(或任何数据库)。你有两个选择:
可以在Prometheus docs上找到信息。
【讨论】:
传统数据库(如 MySQL 和 PostgreSQL)并未针对 Prometheus 收集的时间序列数据进行优化。存在更好的解决方案,它们需要更少的存储空间,并且在插入和选择方面工作得更快。
Prometheus 支持remote storage。启用后,它将所有新数据存储在本地存储和远程存储中。远程存储数据库有多种选择,需要权衡取舍。我建议尝试VictoriaMetrics。它原生支持 Prometheus 的查询语言 PromQL,因此可以很容易地用作 Grafana 中的 Prometheus 数据源。
【讨论】:
https://blog.timescale.com/prometheus-ha-postgresql-8de68d19b6f5
【讨论】:
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'
【讨论】: