Skip to content

Instantly share code, notes, and snippets.

@jderrett
Created August 26, 2015 02:00
Show Gist options
  • Save jderrett/dda21708fb66db710bca to your computer and use it in GitHub Desktop.
Save jderrett/dda21708fb66db710bca to your computer and use it in GitHub Desktop.
Find Librato EC2 CPUUtilization where box is below a threshold for a certain amount of time
import librato
username = 'foo@example.com'
token = '1234abcd'
api = librato.connect(username, token)
metric_name = 'AWS.EC2.CPUUtilization'
source = '*' # Use source name or display name here to filter stuff
# cpu util
threshold = 1.0
print "Getting hourly measurements for last 4 hours with threshold less than " + str(threshold)
measurements = api.get(metric_name, source=source, count=4, resolution=3600).measurements
for source in measurements:
averages = [m['value'] for m in measurements[source]]
# If filtering results in the exact same array, then all measurements were below the threshold
if filter(lambda x: x < threshold, averages) == averages:
print source
# print averages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment