我想用boto3和数学表达式创建磁盘读取吞吐量IOPS cloudwatch警报,但我有错误 错误 “errorMessage”:“调用PutMetricAlarm操作时发生错误(ValidationError):MetricDataQuery Expression和MetricStat参数是互斥的,您已经指定了这两个参数。”
代码
from __future__ import print_function
from string import Template
import json
import boto3
def lambda_handler(event, context):
CW_client = boto3.client('cloudwatch', region_name='eu-west-1')
volume_id = 'vol-01903a31c2c4d5690'
response7 = CW_client.put_metric_alarm(
AlarmName='Disk-Read-Throughput-IOPS',
AlarmDescription='Disk-Read-Throughput-IOPS',
ActionsEnabled=True,
AlarmActions=[
'topic',
],
MetricName='VolumeReadOps',
Namespace='AWS/EBS',
Statistic='Sum',
Dimensions=[
{
'Name': 'VolumeId',
'Value': 'volume_id'
},
],
Period=300,
EvaluationPeriods=3,
DatapointsToAlarm=3,
Threshold=600.0,
ComparisonOperator='GreaterThanThreshold',
Metrics=[
{
'Id': 'm1',
'MetricStat': {
'Metric': {
'Namespace': 'AWS/EBS',
'MetricName': 'VolumeReadOps',
'Dimensions': [
{
'Name': 'VolumeId',
'Value': 'volume_id'
},
]
},
'Period': 300,
'Stat': 'Sum',
},
'Expression': 'SUM(METRICS())/300',
'Label': 'Expression1',
'Period': 300
},
],
)
MetricStat
和Expression
放在同一个Metric
对象中,需要将它们分开。你知道吗Metric
对象,正好1可以返回数据,其余的应该有'ReturnData': False
,这意味着数据将在表达式中使用,但不会在图上产生单独的行(您只需要1行,即表达式生成的行)。你知道吗Metric
列表,则不能使用顶层的Namespace
、MetricName
和Dimension
定义度量,因此需要删除这些度量。你知道吗这应该有效(就指标而言,不确定行动部分):
相关问题 更多 >
编程相关推荐