如何在Prometheus中获得真实计数指标?
当前,计数指标提供运行信息-直到现在为止,有多少个请求到达某个端点。
但是我希望某天从9:00 AM到5:00 PM这样的数字,我的端点受到攻击的次数是多少?可以在上午9:00将计数器值视为0并进行计算吗?
答案 0 :(得分:0)
尝试将范围查询API与start
和end
时间戳结合使用:
文档:https://prometheus.io/docs/prometheus/latest/querying/api/
query=<string>: Prometheus expression query string.
start=<rfc3339 | unix_timestamp>: Start timestamp.
end=<rfc3339 | unix_timestamp>: End timestamp.
step=<duration | float>: Query resolution step width in duration format or float number of seconds.
timeout=<duration>: Evaluation timeout. Optional. Defaults to and is capped by the value of the -query.timeout flag.
答案 1 :(得分:0)
您应该能够使用新的 @
修饰符 https://prometheus.io/docs/prometheus/2.26/querying/basics/#modifier
我假设这样的事情有效:
http_requests_total - (http_requests_total @ start())
他们有一篇关于它的博文:https://prometheus.io/blog/2021/02/18/introducing-the-@-modifier/