Thank you for this question. You are right about a lot of things here. Below I have explained a few pointers, that can help in writing your queries.
The following statement needs to be changed, for proper use of the
stats count() by consumer, controller, action, bin(15m)
- In the above statement, you might have observed an error (on hovering your mouse on the underlined red-lines in your query on console) stating that
bin()is not valid in this position - because, EOF or other applicable keywords are expected after
byin the query. For example
stats count(action = 'test-action') by bin(15m)would be valid.
count()expects parameters i.e. either
count(fieldName: LogField). You can also use
*as your parameter like this -
count(*). Read more here.
Coming to your use case to count number of requests for a specific consumer - for example: to count the number of log events for consumer "test-app-1", change your query to something like the following:
filter @logStream = 'someLogStream' and consumer = 'test-app-1' | fields @timestamp, @message | stats count(*) by bin(15m)
Notice that I have used the
filter statement in order to only fetch the results for a specific consumer, feel free to experiment with such options for other filtering that you might want to perform.
I recommend reading the AWS documentation titled "CloudWatch Logs Insights query syntax". Specifically, for this question - the sections "Matches and regular expressions in the filter command"  & "Supported operations and functions"  can be helpful in getting more clarity & for further learning.
I hope this answer helps in starting with your analysis using Log Insights queries. Feel free to comment on any clarification needed.
CloudWatch log insight query to get application accessed browser
Nested query Cloudwatch Log Insightsasked 3 years ago
Cloudwatch insightsasked 6 months ago
Cloudwatch Log Insights - Line Chart Issuesasked 17 days ago
How to visualize cloudwatch logs with group by fields using a line chartAccepted Answer
PutLogEvents with timeStamp in past breaks Cloudwatch Insightsasked a year ago
Specific Cloudwatch log groups not responding to queriesasked 8 months ago
Cloudwatch Log Insights doesn't find logs from the first Lambda Invocationasked 3 months ago
Cloudwatch Log Insights sum-by query returning differing results each runasked 2 months ago
AWS CloudWatch Log Insights Generate URLasked 3 months ago