martinrusev
3/12/2015 - 7:15 PM

rds.py

from datetime import datetime
from boto.ec2.cloudwatch import CloudWatchConnection

# Create the connection to Cloud Watch
cw = CloudWatchConnection(
    aws_access_key_id=<aws_access_key>,
    aws_secret_access_key=<aws_secret_key>
)

metrics = ["CPUUtilization",
    "DatabaseConnections",
    "FreeableMemory",
    "FreeStorageSpace",
    "ReadIOPS",
    "ReadLatency",
    "ReadThroughput",
    "SwapUsage",
    "WriteIOPS",
    "WriteLatency",
    "WriteThroughput",
]

data = {}
for metric in metrics:
# Actual call to the CloudWatch API to get the stats
    result = cw.get_metric_statistics(
        300, # Granularity
        datetime.utcnow() - datetime.timedelta(seconds=600), # Start
        datetime.utcnow(), # End
        metric, # Metric name
        'AWS/RDS', # Namespace, (AWS/ElastiCache, AWS/RDS)
        'Average', # Statistics
        dimensions={'DBInstanceIdentifier': '<db_id>'} # Dimensions
    )

print results