How to parse slow query log from cloudwatch insights

Viewed 18

How to parse mysql slow query logs from cloudwatch insights.

message looks like below

# User@Host: abc_ro[abc_ro] @ [x.x.x.xxx]
# Thread_id: 4935648 Schema: mytable QC_hit: No
# Query_time: 1.282014 Lock_time: 0.000154 Rows_sent: 6 Rows_examined: 964382
# Rows_affected: 0
use mydummydb;
SET timestamp=1662984070;
SELECT * FROM mytable
1 Answers

Below will parse the query time and query

parse @message /Query_time:\s*(?<Query_time>[0-9]+(?:\.[0-9]+)?)\s*Lock_time:\s*(?<Lock_time>[0-9]+(?:\.[0-9]+)?)[\s\S]*?;/
| parse @message /SET timestamp=\d+;\n(?<Query>[^;]*)/
Related