如何设置 Pushgateway 指标过期的保留时间?

Car*_*tos 6 prometheus prometheus-pushgateway

我将 Pushgateway 与 Prometheus 一起使用,一切正常,但几周后 Pushgateway 崩溃了……看看有大量不再使用的指标,手动删除它们几乎是不可能的……所以 ->

有没有一种方法可以使用 TTL 或其他一些保留设置(例如按大小或按时间)来使 Pushgateway 指标过期?...或者也许两者兼而有之?

注意:我在 Prometheus 的邮件列表中读到,很多人在一年前或更长时间前就需要这样的东西......到目前为止唯一的答案是 -> 这不是 Promethean 的方法......真的吗?...常见,如果这对很多人来说确实很痛苦,也许应该有更好的方法(即使这不是普罗米修斯的方法)

Mic*_*bez 6

假设您想要在与组相关的指标变得太旧时删除它们(对于太旧的给定定义),您拥有push_time_seconds由 Pushgateway 自动定义的指标。

push_time_seconds{instance="foo",job="bar",try="longtime"} 1.598280005888635e+09
Run Code Online (Sandbox Code Playgroud)

有了这些信息,您可以编写一个脚本来请求/获取该指标,并用该值标识旧的数据组 ( {instance="foo",job="bar",try="longtime"})。该 API 允许您删除与旧数据相关的指标:

 curl -X DELETE http://pushgateway:9091/metrics/job/bar/instance/foo/try/longtime
Run Code Online (Sandbox Code Playgroud)

这可以通过几行 bash 脚本或 python 来完成。


Din*_*hai 6

没有得到Prometheus团队的积极回应。所以实施了同样的做法。

https://github.com/dinumathai/pushgateway

docker run -d -p 9091:9091 dmathai/prom-pushgateway-ttl:latest --metric.timetolive=60s
Run Code Online (Sandbox Code Playgroud)