首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建具有多个指标和数学表达式的云监控告警(python3)

创建具有多个指标和数学表达式的云监控告警(python3)
EN

Stack Overflow用户
提问于 2021-03-26 01:40:21
回答 1查看 230关注 0票数 1

这里是一个使用boto3使用过多指标和数学表达式创建cloudwatch告警的示例。asg_name :自动伸缩组名

代码语言:javascript
复制
import boto3
cloudwatch = boto3.client('cloudwatch', region_name="eu-west-1")
def create_cloudwatch_alarm(asg_name):
    cloudwatch.put_metric_alarm(
        ActionsEnabled=True,
        AlarmName=asg_name,
        ComparisonOperator='GreaterThanThreshold',
        DatapointsToAlarm=3,
        EvaluationPeriods=3,
        Metrics=[{'Expression': 'IF(m1 > m2, 1, 0)',
                  'Id': 'e2',
                  'Label': 'Compare Running vs desired capacity',
                  'ReturnData': True},
                 {'Id': 'm1',
                  'MetricStat': {'Metric': {'Dimensions': [{'Name': 'AutoScalingGroupName',
                                                            'Value': asg_name}],
                                            'MetricName': 'GroupDesiredCapacity',
                                            'Namespace': 'AWS/AutoScaling'},
                                 'Period': 300,
                                 'Stat': 'Average'},
                  'ReturnData': False},
                 {'Id': 'm2',
                  'MetricStat': {'Metric': {'Dimensions': [{'Name': 'AutoScalingGroupName',
                                                            'Value': asg_name}],
                                            'MetricName': 'GroupInServiceInstances',
                                            'Namespace': 'AWS/AutoScaling'},
                                 'Period': 300,
                                 'Stat': 'Average'},
                  'ReturnData': False}],
        Threshold=0.1,
        TreatMissingData='missing'
    )
EN

回答 1

Stack Overflow用户

发布于 2021-09-21 01:46:54

根据亚马逊网络服务的文档,您只能使用指标数学:https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create-alarm-on-metric-math-expression.html在最多10个指标上创建警报

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66804857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档