在谷歌云监控中获取随时间变化的比率



我正在运行一个查询,将数据与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

只需将最后一个表操作更改为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-函数https://cloud.google.com/monitoring/mql/reference?hl=en#sub-功能

关于:

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

文件:

  • https://cloud.google.com/monitoring/mql/examples#qlx-比率
  • https://cloud.google.com/monitoring/mql/examples#qlx-随时间变化的并集

最新更新