Created
August 26, 2015 02:00
-
-
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
This file contains 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 librato | |
username = '[email protected]' | |
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