以下是我用于检索Redshift的PercentageDiskSpaceUsed
指标的Python脚本。
我已从上一篇文章中更改了我的代码。当我使用boto3编写脚本时,它无法正常工作。但是在使用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)
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'}]))
答案 0 :(得分:2)
您似乎还需要提供 int status;
pid_t child_id;
child_id = fork();
if (child_id == 0)
{
// put child code here
exec(opens second process);
}
if (child_id < 0)
{
perror("fork failed\n");
exit(EXIT_FAILURE);
}
while(child_id != 0)
{
//parent process
//do fancy math stuff here
// pipe
//open pipe
//converted math to "string" to pass to other program
// use fprintf to send data to other program
fprintf(fp,"%s",str);
//close pipe
//**************************************************
//this block doesn't work, always returns 0
if (WIFEXITED(status)){
int returned = WEXITSTATUS(status);
printf("exited normally with status %d\n",returned);
}
//***************************************************
return 0;
。
首先,通过AWS Command-Line Interface (CLI)
获取指标Dimensions
(根据您的特定需求调整群集名称和时间段。)
要发现可用的命名空间和维度值,请使用:
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'
答案 1 :(得分:0)
尝试使用较新的StartTime和EndTime(例如March)或不同的句点(尝试3600)。
您设置的时间段为600,即10分钟。要在10分钟内构建响应,CloudWatch需要两个5分钟的数据点,5分钟的数据点仅保留63天:http://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html
您要求提供1月份的数据,这是过去63天以上的数据。