Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Amazon Cloudwatch Insights, how do you take a statistic of a statistic?

I am using AWS Cloudwatch Insights and running a query like this:

fields @message, @timestamp
| filter strcontains(@message, "Something of interest happened")
| stats count() as interestCount by bin(10m) as tenMinuteTime
| stats max(interestCount) by datefloor(tenMinuteTime, 1d)

However, on the last line, I get the following error:

mismatched input 'stats' expecting {K_PARSE, K_SEARCH, K_FIELDS, K_DISPLAY, K_FILTER, K_SORT, K_ORDER, K_HEAD, K_LIMIT, K_TAIL}

It would seem to mean from this that I cannot take multiple layers of stat queries in Insights, and thus cannot take a statistic of a statistic. Is there a way around this?

like image 305
TheHans255 Avatar asked Sep 18 '20 17:09

TheHans255


People also ask

What is statistic in CloudWatch?

Statistics are metric data aggregations over specified periods of time. When you graph or retrieve the statistics for a metric, you specify the Period of time, such as five minutes, to use to calculate each statistical value.


1 Answers

You cannot currently use multiple stat commands and from what I know there is no direct way around that at this time. You can however thicken up your single stat command and separate by comma, like so:

fields @message, @timestamp
| filter strcontains(@message, "Something of interest happened")
| stats count() as @interestCount, 
max(interestCount) as @maxInterest, 
interestCount by bin(10m) as @tenMinuteTime

You define fields and use functions after stats and then process those result fields.

like image 154
Ozone Avatar answered Sep 28 '22 05:09

Ozone