- Newest
- Most votes
- Most comments
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 bin()
function:
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 afterby
in the query. For examplestats count(action = 'test-action') by bin(15m)
would be valid. count()
expects parameters i.e. eithercount()
orcount(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" [1] & "Supported operations and functions" [2] 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.
Happy learning!
Relevant content
- asked 5 years ago
- asked a year ago
- asked 8 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago