【问题标题】:Get ratios with time shift in Google Cloud Monitoring在 Google Cloud Monitoring 中获取随时间变化的比率
【发布时间】:2021-08-07 16:25:08
【问题描述】:

我正在运行一个查询,它将数据与 7 天前的数据进行比较。查询仅显示是否存在差异。它不反映差异是增加还是减少。

我正在寻找的是一条中心 0 线,带有一个折线图,显示当前数据是上周数据的增加还是减少,(理想情况下)以百分比表示。

fetch generic_node
| metric 'custom.googleapis.com/myCustomMetric'
| group_by 4h, [row_count: row_count()]
| {value [v_now: val()] ; time_shift 1w}
| join | div

【问题讨论】:

    标签: stackdriver google-cloud-stackdriver google-cloud-monitoring


    【解决方案1】:

    只需将最后一个表操作更改为sub:

    fetch generic_node
    | metric 'custom.googleapis.com/myCustomMetric'
    | group_by 4h, [row_count: row_count()]
    | {value [v_now: val()] ; time_shift 1w}
    | join | sub
    

    请注意,在join 表操作之后,您会得到一个包含两个值列的时间序列表——第一列是当前数据,第二列是上周数据。下面的算术函数(算术运算符的文本名称)充当表操作快捷方式,通过在两个值列上执行该算术函数来生成单个值列。

    div这里的意思是

    | value div(val(0), val(1))
    

    这就是为什么你得到一个比率。而sub 的意思是

    | value sub(val(0), val(1))
    

    您可以在哪里获得差异。

    https://cloud.google.com/monitoring/mql/reference?hl=en#div-func https://cloud.google.com/monitoring/mql/reference?hl=en#sub-func

    【讨论】:

      【解决方案2】:

      怎么样:

      fetch generic_node
      | metric 'custom.googleapis.com/myCustomMetric'
      | group_by [], [row_count: row_count()]
      | {value [v_now: val()] ; time_shift 1w}
      | join | div
      

      或者

      fetch generic_node
      | metric 'custom.googleapis.com/myCustomMetric'
      | group_by [], mean(val())
      | {
          ident
        ;
          time_shift 1w
        }
      | join | div
      

      文档:

      【讨论】:

      • 您的第一个查询返回的结果与我已有的非常相似。 mean 查询只返回一个实心 1。我正在寻找的是一个显示增加/减少的 +/- 图表。我开始怀疑这是否由 1 的值表示
      猜你喜欢
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多