在Grafana中,我使用PromQL向Prometheus查询有关文档计数的ElasticSearch数据。我想用图表说明文档摄取的速率,以便可以看到ElasticSearch在一天中的什么时候出现峰值或已经停止摄取。
我正在使用时间范围(10m对60m)来创建两个不同的图形,如下所示。我希望在任何给定时间都可以看到两个查询的文档摄取率相同,但是显然不是这种情况(请参见下图-峰值在不同时间结束)。
我的问题是:
图1
使用的查询: sum(rate(rate(elasticsearch_indices_docs_total {cluster =〜“ elasticsearch-dev”,index =〜“ containerlogs-dev。*”} [10m]))
GRAPH 2
使用的查询: sum(rate(rate(elasticsearch_indices_docs_total {cluster =〜“ elasticsearch-dev”,index =〜“ containerlogs-dev。*”} [60m]))
请注意区别– GRAPH1在10:51,而GRAPH2在11:40。查询之间的差异在于时间范围,即10m与60m
有用的笔记:
从Promql文档中
rate()
rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. Also, the calculation extrapolates to the ends of the time range, allowing for missed scrapes or imperfect alignment of scrape cycles with the range's time period.
The following example expression returns the per-second rate of HTTP requests as measured over the last 5 minutes, per time series in the range vector:
rate(http_requests_total{job="api-server"}[5m])
rate should only be used with counters. It is best suited for alerting, and for graphing of slow-moving counters.
Note that when combining rate() with an aggregation operator (e.g. sum()) or a function aggregating over time (any function ending in _over_time), always take a rate() first, then aggregate. Otherwise rate() cannot detect counter resets when your target restarts.