Alarm for long running query in mysql

0

Hi We have Aurora Mysql cluster . What is the best way to set alarm for long running queries for example queries that are running more than one hour.

Query
asked a month ago176 views
2 Answers
2
Accepted Answer

Hello.

If I were to output slow query logs, I would set up a metrics filter so that they are registered in metrics at the same time they are output.
Create an alarm for that metric.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.MySQL.LogFileSize.html

Alternatively, you can set a subscription filter on the slow query log log group and have it notified via Lambda.
Unlike metric filters, subscription filters allow you to easily create a configuration that notifies you of log messages as they are.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#LambdaFunctionExample

profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
  • Thank you for your response , I'm bit confused about setting slow query time. for example if I wanted to log queries that has been running for 2 hours what value should I give ? How do I use this value to set up the alarm? How do I auto delete/rotate this file ?

  • for example if I wanted to log queries that has been running for 2 hours what value should I give ?

    If you set "long_query_time" in the parameter group to "7,200", only queries that took more than 2 hours will be output to the log. https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.MySQL.LogFileSize.html#USER_LogAccess.MySQL.Generallog

    How do I use this value to set up the alarm?

    In the case of metrics filters, slow queries occur when metrics are registered, so I think you should set the alarm threshold to 1 or higher.

    How do I auto delete/rotate this file ?

    I think you should set the retention period for the CloudWatch Logs log group. https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html

  • Thank you.

    In the case of metrics filters, slow queries occur when metrics are registered, so I think you should set the alarm threshold to 1 or higher.

    As I went thru cloudwatch, I’m not sure how would I create metrics pattern for slow queries? Do you have any example How do I set this metric pattern to set the alarm

  • If you want to register all queries output to the slow query log in metrics, I think you can register them all by leaving the filter pattern empty. https://aws.amazon.com/jp/blogs/database/monitor-amazon-rds-for-mysql-and-mariadb-logs-with-amazon-cloudwatch/

  • So What am looking here is to find long running queries that currently being executing/running more than certain amount of time . Which is something I need to get alerts. Slow queries output we get after queries being executed. Hope you can help

0

But from my understanding this would only help queries that already executed. I’m looking for queries that are running or currently executing for certain period of time .

Query
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions