【问题标题】:How to substract metrics with different labels?如何减去具有不同标签的矩阵?
【发布时间】:2020-07-13 00:17:59
【问题描述】:

我需要计算两个不同的指标:

totalcurrent{app}

目前有效的表达方式:

max total offset 30s - max current{app="myapp"}

这给了我一个号码,我用它来提醒myapp 的某些进程的速度。

但是,我有多个应用程序。所以我想获得每个应用程序的差异。但是当我尝试通过应用获取最大值时,prometheus 不再计算差异,因为这两个指标具有不同的标签:

表达式 max total offset 30s - max by (app) (current)

输出 {}(无)

那是因为各个计算的结果有不同的标签:

total{}current{app="someapp"}

我希望有一个 prometheus 函数可以将标签添加到 total,以便为所有应用生成相同的指标(当然这已经有点讨厌了)。

如何获得一个返回每个 app 差异的表达式?

预期结果

{app="myapp"}    333
{app="someapp"}    9

【问题讨论】:

    标签: prometheus


    【解决方案1】:

    如果我理解正确,减法左侧有一个没有标签的指标,右侧有多个指标。

    这似乎是one to many matching的情况:

     max total offset 30s - on() group_right max by (app) (current)
    

    on() 子句表示标签应该被忽略,group_right 表示 many 边是右手边。

    【讨论】:

    • 像魅力一样工作!感谢您向我指出该文档。
    猜你喜欢
    • 2017-04-06
    • 1970-01-01
    • 2021-12-30
    • 2013-09-27
    • 2018-08-11
    • 2017-04-08
    • 2013-11-08
    • 2018-10-14
    • 1970-01-01
    相关资源
    最近更新 更多