Skip to content

Instantly share code, notes, and snippets.

@danielfl
Created June 26, 2017 13:44
Show Gist options
  • Save danielfl/6a6f229d2ca568ec4d4f3c32f81c64df to your computer and use it in GitHub Desktop.
Save danielfl/6a6f229d2ca568ec4d4f3c32f81c64df to your computer and use it in GitHub Desktop.
from boto import ec2
import requests
import urllib2, base64
for reg in ec2.regions():
wasted_space = 0
print "connecting to ", reg.name
try:
conn = ec2.connect_to_region(reg.name)
vol = conn.get_all_volumes()
for v in vol:
if v.status == "available":
wasted_space = wasted_space + v.size
if wasted_space > 0:
print "sending metrics to pushgateway"
url = "https://push/metrics/job/audit"
user=""
password=""
metric = 'ebs_unused_gb { region="'+reg.name+'" } '+str(wasted_space)+"\n"
print "metrica=",metric
r=requests.post(url, auth=(user,password),
data=metric,
headers={'Content-Type': 'application/octet-stream'})
print r.status_code
print r.text
except Exception, e:
print "could not connect to ", reg.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment