当使用boto3推送度量时,AWS CloudWatch警报处于“数据不足”状态

2024-09-29 19:36:27 发布

您现在位置:Python中文网/ 问答频道 /正文

报警长时间处于不足状态。在

指标图:

enter image description here

这是创建警报的代码:

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'
)

还尝试为自定义度量创建度量警报,但这有不同的问题。在

{{cd2>中的所有度量都是自定义的。在

尝试给出Namespace='Custom/EC2'Namespace='EC2'Namespace='Custom/EC2'Namespace='AWS/EC2'Namespace='Custom/Custom'。在

但这些案子中的任何一个。它并没有达到受人尊敬的标准。在

enter image description here


Tags: clientaws报警度量状态createcustom警报
2条回答

你是如何推动定制指标的?您是使用自己的脚本还是使用CloudWatch代理?在

如果是CloudWatch代理-那么检查代理的日志。 https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html#CloudWatch-Agent-troubleshooting-loginfo

如果使用某些sdk(如boto3),则打印响应或添加调试 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/boto3.html

我试过用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

您在EC2实例中启用了detailed monitoring吗?在

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.

您将在60秒周期内配置警报,并在1个数据点上发出警报,因此如果度量不是每分钟发布一次the alarm will go into insufficient data。您可以在EC2实例中启用详细监视,或者将报警周期更改为300秒。在

相关问题 更多 >

    热门问题