I have microservice that sends some custom metrics to AWS CloudWatch. Metric name consists of package name and some other data. For example gauge.com.example.test.time and gauge.com.example.test2.time and so on
Now I need to create some alarms based on this metrics. Is it possible to specify some reqular expression in metric name field when you create CloudWatch alarm instead of manual creation of separate alarm for each metric?
I tried such things: gauge.com.example..time gauge.com.example.*.time gauge.com.example.(\w).time and many other things but without success.
It is now possible to create aws alarms based on a Metric Math Expression.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create-alarm-on-metric-math-expression.html
Not possible. From Creating Amazon CloudWatch Alarms
You can create a CloudWatch alarm that watches a single metric.
Related
I have around 100+ cloudwatch alarms.
I want to find which alarms use custom metrics and which one uses default metrics?
I need to find such a list so that I can convert default metric alarms into custom metrics.
Note:- the alarms have been created by CDK.
Is there a way I can use AWS CLI and find out this?
I am trying to send an SNS notification when a backup in the backup vault fails twice consecutively. Is there a CloudWatch alarm or any other way to do this in CloudFormation?
You can use CloudWatch metrics for this purpose and then setup alarms based on the thresholds that you need.
You can find the list of Metrics that are emitted to CloudWatch in this document: https://docs.aws.amazon.com/aws-backup/latest/devguide/cloudwatch.html
For instance you can setup an alarm on NumberOfBackupJobsFailed metric.
I have alarms in AWS Cloudwatch but at night I keep getting False positives due to low volumes. How can I set up an alarm so that it only triggers at certain times of the day? Or how do you suggest approaching this problem?
Using AWS CLI you can disable cloudwatch alaram using the following command:
aws cloudwatch disable-alarm-actions --alarm-names "alarm name"
And then enable it again using this command:
aws cloudwatch enable-alarm-actions --alarm-names "alarm name"
You scheduled this disable/enable using cronjob for example.
You can automate this by creating an EventBridge rule where you specify a cron or schedule expression that runs a lambda function.
Then, you can use your Lambda function to enable or disable an alarm (or even multiple alarms together) according to your desired schedules.
disable_alarm = client.disable_alarm_actions(AlarmNames=alarm_names)
Here's a good tutorial: https://medium.com/geekculture/terraform-structure-for-enabling-disabling-alarms-in-batches-5c4f165a8db7
Alternatively, I found that it is possible to create a metric based on a Math expression where I could say for example:
IF(Invocations > threshold, metric, 0)
And this will output 0 at night where the Invocations volume is less than the threshold.
Then I could create an alarm on top of this new metric.
I would like to create a cloudwatch alarm for the sns metric NumberOfMessagesPublished on a new sns topic. If I attempt to do this before I trigger the topic (and there is no data for it) then the option to create an alarm does not exist in the web console.
How can I do this with the web console? Is using a cli tool the only option?
I noticed that too -- you cannot select a metric until the data has been sent to CloudWatch.
I suspect that CloudWatch actually doesn't have any visibility into metrics until they are sent from the originating service into CloudWatch. Thus, it can't populate the console because it doesn't know what data will be sent. That would be a nice, loosely-coupled design.
My experiments show that it is possible create an alarm via the AWS Command-Line Interface (CLI) on metrics that do not exist -- even within the EC2 namespace. That's the way to go!
I suggest you to use Cloudformation. It is the best way to create resources stack in AWS and overall you can easily experiment with it and delete everything when you are done. Here there is a sample application that uses Cloudformation and Cloudwatch https://github.com/awslabs/cloudwatch-dashboards-cloudformation-sample
The manual solution I went with was to create the sns topic and then use the Publish to topic option in the sns menu to send out a test message to my subscribers. This creates a set of notifications without the need to set off the cloudwatch rule. After this the option appears in the cloudwatch alarm creation menu.
The other CLI options would be better for automation.
Yes, it is possible. The AWS Official Documentation answers your question. Just to quote the relevant lines:
You can create an alarm for a custom metric before you've created that custom metric. For the alarm to be valid, you must include all of the dimensions for the custom metric in addition to the metric namespace and metric name in the alarm definition.
I am trying to create an alarm for "FreeStorageSpace" metric and units it takes is Bytes. What, however, I am trying to do is create an alarm using percentages (send an alarm is FreeStorageSpace < 10%) and not hardcode values. How can I create a CFT for that and reuse it for instances having different storage values.
Any help is appreciated.
Thanks
You can not use % value while creating the FreeStorageSpace alarm in CloudWatch. Also, the alarms in AWS are on per instance basis. You can not create a generic alarm for multiple instances. Hence, you may use numeric value for defining the alarm.