【问题标题】:How to get the first and last element of a range vector in promql如何在promql中获取范围向量的第一个和最后一个元素
【发布时间】:2021-10-23 23:43:46
【问题描述】:

我正在尝试获取由类似于此的查询返回的范围向量中的第一个和最后一个元素:

container_memory_usage_bytes[1h]

在结果集中,我得到一个小时内每个 pod 的时间戳和内存值列表。

3863654400 @1629726924.874
3863539712 @1629726955.72
3863900160 @1629726984.032
3863937024 @1629727016.102
3863515136 @1629727049.814
3863703552 @1629727077.533
3863506944 @1629727104.48
3863896064 @1629727128.676

如果我只想知道这个数组的第一个索引和最后一个索引是什么,即每个 pod 的一小时第一条记录和一小时最后一条记录,我将如何构造查询?

【问题讨论】:

    标签: prometheus promql


    【解决方案1】:

    您可以按照here 的描述使用last_over_time 函数。

    last_over_time(range-vector):指定区间最近的点值。

    last_over_time(container_memory_usage_bytes[1h])
    

    我没有找到 Prometheus 的 first_over_time。也许在 Prometheus 中还有另一种方法可以做到这一点。虽然,Grafana 的 first_over_timeit is shown here。正如@valyala 所说,如果您安装和配置VictoriaMetrics,您可以使用它as described here

    【讨论】:

    • first_over_time 函数存在于 VictoriaMetrics 的 MetricsQL 中 - see these docs
    • 确实如此,我也看到了。但是我将如何在普罗米修斯仪表板中使用VictoriaMetrics?只有安装了docs.victoriametrics.com/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 2016-07-07
    • 1970-01-01
    • 2012-04-21
    • 2016-06-05
    相关资源
    最近更新 更多