Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cloudwatch Logs Insights find logs close to another log or timestamp

On AWS Cloudwatch Log Insights, often after you filter your logs and find an interesting log message you want to see what was happening right before or after that message.

What is the best way to find log messages right next to another message?
I imagine a good way is to filter based on @tiemstamp and they conveniently provide a date_floor function, but I cannot figure out the syntax that works for equality to timestamps.

like image 681
Ali Avatar asked Mar 04 '19 17:03

Ali


People also ask

How do I filter timestamp in CloudWatch insights?

Filtering on timestamp is done with the range selector on the top right in the Logs Insights Console or with the startTime and endTime parameters on the StartQuery API.

How do I search multiple CloudWatch logs?

To search all log entries for a time range using the consoleOpen the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Log groups. For Log Groups, choose the name of the log group containing the log stream to search. Choose Search log group.

How do you aggregate CloudWatch logs?

To run a query with an aggregation functionOpen the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Logs, and then choose Logs Insights. In the Select log group(s) drop down, choose one or more log groups to query.


1 Answers

In Logs Insights, if you query for:

fields @timestamp, @message, @logStream
     | filter @message like /<Your Log Message>/

you'll get a link where you can access the log stream. Clicking there will bring you right to the context before/after the log you're interested in.

It's a fair bit of work for something that should be a single click but it's the only work-around I'm aware of. Feel free to go bug the AWS team to build this as a 1-click feature right from the logs themselves.

Edit: Something I didn't know when I wrote this answer: this trick only works if you're querying a single log group. If you're querying multiple, it still shows the logStream but it's not clickable.

like image 138
Eric Le Fort Avatar answered Sep 24 '22 18:09

Eric Le Fort