amazon-web-services - 亚马逊CloudWatch没有返回红移度量

  显示原文与译文双语对照的内容
93 3

下面是我的python 脚本部分,用来检索红移度量的PercentageDiskSpaceUsed

我已经更改了以前帖子中的代码。 当我使用boto3编写脚本时,它不工作。 但使用boto2编写时。 粘贴两个脚本请检查并更正:-

使用boto2编写脚本:-


from boto.ec2 import cloudwatch


from datetime import datetime, timedelta


import boto



REDSHIFT_REGION = 'ap-south-1'


connection = boto.ec2.cloudwatch.connect_to_region(REDSHIFT_REGION)



def set_time_ranges():


 return {


"start": datetime.utcnow() - timedelta(seconds=600),


"end": datetime.utcnow()


 }



time_range = set_time_ranges()



data = connection.get_metric_statistics(60,time_range["start"], time_range["end"],'PercentageDiskSpaceUsed','AWS/Redshift', 'Average', dimensions={


"ClusterIdentifier": 'test'}) 


print (data)



使用boto3编写脚本:-


import boto3


from datetime import datetime, timedelta



access_key = <xxxxxxxxxxxxxx>


secret_key = <xxxxxxxxxxxxxxx>



def set_time_ranges():


return {


"start": datetime.utcnow() - timedelta(seconds=600),


"end": datetime.utcnow()


}


time_range = set_time_ranges()



client = boto3.client('cloudwatch', aws_access_key_id = access_key, aws_secret_access_key = secret_key, region_name='ap-south-1')


print(client.get_metric_statistics(Period=60, StartTime=time_range["start"], EndTime=time_range["end"], MetricName="PercentageDiskSpaceUsed", Namespace="AWS/RedShift", Statistics=["Average"], Unit="Percent", Dimensions=[{'Name': 'ClusterIdentifier', 'Value': 'test'}]))



时间: 原作者:

129 3

似乎你还需要提供 Dimensions

首先,通过 AWS命令行界面( adv 。CLI ) 获得度量:


aws cloudwatch get-metric-statistics 


--namespace 'AWS/Redshift' 


--metric-name PercentageDiskSpaceUsed 


--start-time 2017-04-22T00:00:00Z 


--end-time 2017-04-22T05:00:00Z 


--period 60 


--statistics Average 


--dimensions Name=NodeID,Value=Shared Name=ClusterIdentifier,Value=lab



( 调整特定需要的群集名称和时间段。)

要发现可用的命名空间和维度值,请使用:


aws cloudwatch list-metrics --namespace 'AWS/Redshift'



然后,这里代码将运行:


import boto3



from datetime import datetime, timedelta



client = boto3.client('cloudwatch',region_name='ap-southeast-2')



client.get_metric_statistics(


 Namespace='AWS/Redshift',


 MetricName='PercentageDiskSpaceUsed',


 Dimensions=[{'Name':'NodeID','Value':'Shared'},


 {'Name':'ClusterIdentifier','Value':'lab'}


 ],


 StartTime=datetime.utcnow() - timedelta(seconds=3600),


 EndTime=datetime.utcnow(),


 Period=60,


 Statistics=['Average']


 )



原作者:
...