Prometheus 警报 - 缺少具有日期标签和时间戳值的成功指标

Prometheus alerts - Absence of succeeded metrics having a date label and a timestamp value

我有一个仪表类型的指标,对于每个操作(标签 step)和给定日期(标签 day 在形式 'yyyy-mm-dd'),存储最后一个成功事件的时间戳。 类似于:

{step_name="Upload table_1", day="2022-01-01"} = 1644354491

例如,我可以检查在“table_1”中上传了“2022-01-01”日的数据多少小时前:

(time() - importer_succeeded_timestamp{day = "2022-01-01", step_name="Upload table_1"})/3600

如果数据未在 table 中上传后的第二天,我需要收到提醒,因此如果仪表值与转换后的日期值“day " 标签,指标不存在。因此,我需要以某种方式将仪表(时间戳)的值与“天”(字符串格式的日期)进行比较。 非常欢迎每一个帮助,我在普罗米修斯指标和警报管理器方面的经验非常有限,但我觉得目前的指标设计是不可能的。

我继续搜索,我发现这是不可能的。

在 Grafana 博客上的这次对话中 https://community.grafana.com/t/how-to-use-a-prometheus-label-as-a-timestamp-for-grafana/54708 他们谈到了:

known limitation with Prometheus. It just wasn’t designed to ingest time-series data where the timestamp is a label.

这里还有一个和我的问题类似的问题Prometheus label comparison with vector timestamp

This isn't possible, label values are opaque strings to Prometheus.

我们找到的唯一解决方案:添加具有相同标签集的新指标,其值为从“日期标签”到执行时刻的秒数。像这样,可以同时使用 AND 中的指标,因为这里是这样写的 https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators:

vector1 and vector2 results in a vector consisting of the elements of vector1 for which there are elements in vector2 with exactly matching label sets. Other elements are dropped. The metric name and values are carried over from the left-hand side vector.