Created
February 13, 2011 02:03
-
-
Save davidcoallier/824349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import os | |
import sys | |
from boto.exception import BotoServerError | |
import boto.ec2.cloudwatch.metric | |
import boto | |
AWS_ACCESS_KEY = "XXX" | |
AWS_SECRET_KEY = "YYY" | |
class Error(Exception): | |
pass | |
class InstanceDimension(dict): | |
def __init__(self, name, value): | |
self[name] = value | |
def main(argv): | |
try: | |
c = boto.connect_cloudwatch(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
end = datetime.datetime.now() | |
start = end - datetime.timedelta(hours=2) | |
stats = c.get_metric_statistics( | |
60, | |
start, | |
end, | |
'CPUUtilization', | |
'AWS/EC2', | |
'Average', | |
InstanceDimension("InstanceId", 'i-7781301b') | |
) | |
print stats | |
except BotoServerError as serverErr: | |
print serverErr | |
print json.dumps({"error":"Error retrieving CloudWatch metrics."}) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment