Skip to content

Instantly share code, notes, and snippets.

@cgbystrom
Created March 5, 2012 10:53
Show Gist options
  • Save cgbystrom/1977863 to your computer and use it in GitHub Desktop.
Save cgbystrom/1977863 to your computer and use it in GitHub Desktop.
Prints usage for Amazon Route 53 zones for a given time period
"""
Prints usage for Route 53 for a given time period
(exported from the Amazon Route 53 usage console).
"""
import csv
route53_reader = csv.reader(open('route_53_usage_february_2012.csv', 'rb'), delimiter=',', quotechar='|')
route53_reader.next() # Skip header
zone_lookup = dict('INSERT_ZONE_ID'='mydomain.com')
def lookup_zone(zone):
n = zone_lookup.get(zone, None)
if not n: return zone
return n
dns_requests = {}
for row in route53_reader:
if len(row) == 0: continue
zone = row[3]
num_requests = row[6]
if not zone in dns_requests:
dns_requests[zone] = 0
dns_requests[zone] = dns_requests[zone] + int(num_requests)
dns_request_items = dns_requests.items()
dns_request_items.sort(key=lambda t: t[1], reverse=True)
for zone, num_requests in dns_request_items:
print "%25s %11d" % (lookup_zone(zone), num_requests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment