Create Metric Math alarm using single metric in cloudwatch - amazon-web-services

I am trying to create alarm in cloudwatch. I have a metric where I emit 1.0 for success and 0.0 for failure. The SUM statistic is supposed to me give all the successful request while SAMPLE COUNT should give all the requests(including failed one). I want to create an alarm where if SUM(metric)/SAMPLE COUNT(metric) <= threshold it alarms. I am not able to do the same using a single metric. The SAMPLE COUNT option does not show up. Am I expected to create two metrics in order to achieve this in cloudwatch if it is not possible via single metric?

SUM(metric)/SAMPLE COUNT(metric) is the definition of average. Can you use the Average statistic?

Related

How to delete a dimension from aws cloudwatch custom metric

Plotted a cloudwatch custim metric using lambda in aws cloudwatch/ but sent wrong dimension. In api call by mistake i sent swapped values for values / dimension name. now i am getting lot of metrics with 0.896, 0.345 etc dimentions. how to delete the. It iss creating garbage in the metric list.see screenshot for details.
Dimension is part of metric's identity:
A dimension is a name/value pair that is part of the identity of a metric.
Since its not possible to delete any metrics, you can't remove/change dimensions of metrics already in the AWS. You have to wait till it expires after 15 months:
CloudWatch does not support metric deletion. Metrics expire based on the retention schedules described above.
For your case, you have to create new metrics with correct dimension and use that in your plots and alarms.

AWS: Alarming on Metric Math alternative

I am currently in the process of migrating some services to AWS and have hit a bit of a road block. I would like to be able to monitor the error percentage of a Lambda and create an Alarm if a certain threshold is breached. Currently the percentage error rate can be calculated with Metric Math, however alarms cannot be generated from this.
I was wondering if anyone know a way in that I could push the metrics require to calculate the percentage, Error and Invocation, to a Lambda and have the Lambda perform the calculation and create the SNS alarm?
Thanks!
CloudWatch just released the Alarms on MetricMath expressions.
https://aws.amazon.com/about-aws/whats-new/2018/11/amazon-cloudwatch-launches-ability-to-add-alarms-on-metric-math-expressions/
So basically you just need to:
Go to CloudWatch
Go to Alarms
Create Alarm
Add your metrics
Add a MetricMath expression
Optionally, add other properties for the alarm
Add the actions that you want to be executed
More information in their documentation

How to generate AWS CloudWatch Alarm which involves multiple Metrics

Need to generate CloudWatch Alarm for API Gateway and Lambda functions.
For API Gateway CloudWatch Alarm should be generated if 5XX Error count is 10% of total request count at given period (e.g. 5 minutes).
Similarly, We need to add a metric if Maximum Latency 6% of total request count > 4 seconds.
For such type of metric looks like we need a combination of metric like Sum of total requests and than need to calculate percentage of errors.
We have Math Expressions/Metric math which might be used. Is there any other way to achieve this?
Any help is appreciated!
EDIT: Its now possible to create alarms on Metric expressions from the CloudWatch Console.
Original Answer below:
Unfortunately its not possible to create alarms based on Metric expressions in CloudWatch.
Your best bet may be the M of N thresholds in alarms, for example:
If num_of_errors > 5 for 3 datapoints in 5 minutes.
Its not exactly what your asking for, but may be a good start.
Best of luck!

AWS CloudWatch alert on every change in metric

Can you set up CloudWatch to fire an event (which can lead to a Lambda function being called) on every change to a metric? I can see how to fire an even when it meets a boundary via alerts, but I'd like an event on every change.
No.
A CloudWatch Alarm is triggered when a calculated metric goes outside a given bound over a desired time period. It is always a calculated value (eg average, sum, min, max) and is not based upon an individual metric.
That said, if you have very sparse metrics (that don't trigger very often), using COUNT or SUM might be sufficient but it isn't specifically what you are requesting.
If you have a metric that behaves in a predictable way then you can indeed achieve this kind of behaviour.
If you have a metric with a small set of possible values, for example, consider a metric where the value can be 0 or 1.
You could then create a CloudWatch alarm where the threshold is 0 for 1 period and then a second alarm where the threshold is 1 for 1 period.
So basically for each possible value that your metric can be, you would have an alarm. Each of these alarms would trigger an action of your choice e.g. SNS
As I said, this would only work if you have a metric with a known set of possible values, not with a metric that can have unpredictable values.

How can I get the aggregate of two CloudWatch metrics in a single metric?

I want to get average of network input and network output metric as a single metric from Amazon CloudWatch. Is there any way to achieve this or any script or opensource tools available?
You can use CloudWatch Metric Math AVG function to get the average of two metrics:
The AVG of a single time series returns a scalar representing the
average of all the data points in the metric. The AVG of an array of
time series returns a single time series. Missing values are treated
as 0.