0

I want to execute MQL (metric query language) to get sum of all values from "metric.size" column which have the same "metric.id".

the table looks like this

It should be grouped by id, and size column to be the sum of all the size values for matching id, and this within a certain time range.

In SQL it would look something like below: select id, sum(size) from "metric" group by id where ts is bigger X & less than Y

I have tried many variation of the below command; using within, every, window with no luck.

fetch k8s_container | metric 'logging.googleapis.com/user/ingestion-info' | group_by [metric.tenantId], sum(metric.size) | every 13h

Any help would be greatly appreciated. Thank you.

Also i have tried solutions in the below links: Unable to collect data from metric query language MQL - GCP GCP MQL query: getting metrics/minute

1 Answers1

1

I think you need to turn the column you want to aggregate into a value column. metric and resource columns are used in the first argument of group_by operation.

fetch k8s_container
| metric 'logging.googleapis.com/user/ingestion-info'
| value [value.size: metric.size]
| group_by [metric.tenantId], sum(value.size)
| every 13h

BTW, looks like there is no value exported in your table. If the metric.size is the info you want to monitor, I recommend you define it as the value of the metric. logging.googleapis.com/user/ingestion_size or logging.googleapis.com/user/ingestion-info/size might be more readable as a metric name.

Cheng Hou
  • 81
  • 1
  • Thank you for the response @cheng-hou my ingestion-info metric has 5 labels which include both size and tenantId values. also based on my testing sum(metric.size) does the same thing as setting the value.size and then getting the sum of that. I was able to get some data thats matching my actual logs using the below: ` fetch k8s_container | metric 'logging.googleapis.com/user/ingestion-info' | group_by [metric.tenantId], sum(metric.size) | within 1h | window 1h ` but now problem is the inconsistency of the "within" and the time range doesn't work properly when using date literal – Hosein Khosravani Jan 24 '22 at 22:02
  • Can you elaborate on the "within" problem? – Cheng Hou Jan 26 '22 at 00:08