I want to use MQL to get the sum of values in a 30 minute interval from values.
I am currently utilizing the sent message count
metric as it seems to fit my needs. I would like my output to be grouped by the subscription id and sum of all the values in the last 30 minutes .
I have tried a-lot of different combinations to achieve my desired output with no luck.
currently I have this query :
fetch pubsub_subscription
| metric 'pubsub.googleapis.com/subscription/sent_message_count'
| group_by [resource.subscription_id], sum(value.size)
| align rate(30m)
| every 30m
Any help would be greatly appreciated . Thank you
Update:
So far I have gotten closer to my desired output trying this query:
fetch pubsub_subscription
| metric 'pubsub.googleapis.com/subscription/sent_message_count'
| value [value.size: value.sent_message_count]
| group_by [resource.subscription_id], sum(value.size)
| every 30m
this query lets me see a count of messages ex. 18.77M
, 0.39M , etc . However when I add the | align rate(1w)
it turns the value into k/s
instead of M
for ex. 1.29k/s, 0.01 k/s, etc
How do I convert these numbers to a total count of messages ?
MQL has a scale function that can be used to scale a value. In this case, adding a scale function after the align step can be used to scale this to have units as desired.The scale function will multiply a value with one unit by a scale factor that converts it to a value with a different unit.
For example, the expression scale(3 "min", "s") will convert the value 3 with units minutes (min) to the value 180 with units seconds (s). The same amount of time, expressed in different units. The units are given according to the UCUM Standards.