Below is my part of Python script to retrieve Redshift's PercentageDiskSpaceUsed
metric.
I have changed my code from the previous post. When i write script using boto3, its not working. But working when written using boto2. Pasting both the scripts. Please check and correct:-
Script using 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)
Script using 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'}]))
Try using newer StartTime and EndTime (March for example) or a different period (try 3600).
You are setting a period of 600, which is 10 minutes. To construct the response on a 10 min level, CloudWatch needs two 5-min datapoints and 5-min datapoints are retained only for 63 days: http://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html
You are asking for data from January, which is more than 63 days in the past.
It appears that you also need to supply
Dimensions
.First, get the metrics working via the AWS Command-Line Interface (CLI):
(Adjust the cluster name and time period for your particular needs.)
To discover available namespace and dimensions values, use:
This code then works: