Automate Error Detection with CloudWatch Log Alarms

DevOps Engineer | Kubernetes | Python | Terraform | AWS | GCP
Search for a command to run...

DevOps Engineer | Kubernetes | Python | Terraform | AWS | GCP
No comments yet. Be the first to comment.
Tired of shuffling USB cables every time someone in your household or small office needs to print? Wish you could print wirelessly from any device on your network? Well, you're in luck! With the magic of a Raspberry Pi and a few simple commands, you ...

It is quite common to lose the integrity of configmaps/secrets for the following reasons: You have a large team with more than 5 people You do not use any Config/Secret Management Tool Lack of team collaboration Anyway, that's not the point. All...

It's quite common to see your important service account being modified by someone. Don't worry, my friend. Here is how you can track who did what. Login to GCP and navigate to Logging Set a proper timeline from the date-time picker (last X hour or ...

You can speed up your smart tv experience by disabling some annoying, built in apps. First, enable ADB on your Android TV unit. To Activate Developer Options: Navigate to Settings > About. Tap Build number seven times to enable developer mode. Once d...

If you need to automate the process of clicking a button on a webpage using Selenium, this guide will walk you through it effortlessly. Prerequisites You will need the following items. Python3 with selenium module Chrome Browser and Chrome Driver [...

Assume you have a log group in CloudWatch that continuously holds the application logs. If the logs are encoded as JSON, it will be very useful to filter the logs based on specific JSON keys or fields.
Here is the CloudWatch query that filters logs with level = error and aggregates them by the count of occurrences.
fields @timestamp, @message
| filter level = "error"
| stats count(*) by @log
If you want an automated alert every time level = error appears, you can turn it into a CloudWatch Metric Alarm. Use the following command to create such an alarm.
aws cloudwatch put-metric-alarm --cli-input-json file://alarm.json
And here is the alarm.json file that contains all the required information.
{
"logGroupName": "prod-backend/docker/api",
"filterName": "api-error",
"filterPattern": "{ $.level = \"error\" }",
"metricTransformations": [
{
"metricName": "api-error",
"metricNamespace": "api",
"metricValue": "1",
"unit": "count"
}
]
}
Finally, you can connect the api-error metric to an SNS topic to get notified every time an error occurs in the log group.