Alarm is on insufficient state for long time.
Graph of the metric:
This is the code that creates the alarm:
import boto3
# Create CloudWatch client
cloudwatch = boto3.client('cloudwatch')
# Create alarm
cloudwatch.put_metric_alarm(
AlarmName='Web_Server_CPU_Utilization',
ComparisonOperator='GreaterThanThreshold',
EvaluationPeriods=1,
MetricName='CPUUtilization',
Namespace='AWS/EC2',
Period=60,
Statistic='Average',
Threshold=70.0,
ActionsEnabled=False,
AlarmDescription='Alarm when server CPU exceeds 70%',
Dimensions=[
{
'Name': 'InstanceId',
'Value': 'INSTANCE_ID'
},
],
Unit='Seconds'
)
Also tried to create a metric alarm for Custom metrics, but this has different issue.
All the pre-defined metrics are in AWS namespaces
and custom metrics are in Custom namespaces
.
Tried giving Namespace='Custom/EC2'
, Namespace='EC2'
, Namespace='Custom/EC2'
, Namespace='AWS/EC2'
, Namespace='Custom/Custom'
.
But any of those cases. It is not pushing to the respected metric.
Try to send put_metric_alarm
request without Unit
property. The thing is that if you create an alarm based on metrics, you shouldn't have dimension or unit properties defined.
Do you have detailed monitoring enabled in the EC2 instance?
By default, your instance is enabled for basic monitoring. You can optionally enable detailed monitoring. After you enable detailed monitoring, the Amazon EC2 console displays monitoring graphs with a 1-minute period for the instance.
You're configuring the alarm on a 60s period and alarming on 1 datapoint so if the metric is not published every minute the alarm will go into insufficient data . You can enable detailed monitoring in your EC2 instances or change the alarm period to 300 seconds.
How are you pushing custom metrics? Are you using your own script or one of the CloudWatch Agent?
If CloudWatch Agent - then check the Agent's logs. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html#CloudWatch-Agent-troubleshooting-loginfo
If using some sdk (like boto3) print the response or add debug https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html
I tried with the AWS cli-
saws> aws cloudwatch put-metric-data --namespace AWS/EC2 --metric-name Sufyan --value 32 --region ap-southeast-2
An error occurred (InvalidParameterValue) when calling the PutMetricData operation: The value AWS/ for parameter Namespace is invalid.
saws> aws cloudwatch put-metric-data --namespace Custom/EC2 --metric-name Test --value 32 --region ap-southeast-2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.