Skip to content

Instantly share code, notes, and snippets.

@scr512
Created February 27, 2016 05:55
Show Gist options
  • Save scr512/112397effdf1bce78908 to your computer and use it in GitHub Desktop.
Save scr512/112397effdf1bce78908 to your computer and use it in GitHub Desktop.
Sending directory quotas from the Isilon directly to a Graphite (carbon) instance
#!/usr/bin/env python
#Notes
#This is a little hacky given that you can't calculate a utilization percentage on a quota with no hard-threshold. The "hack" is to set the hard value from 0 to 1.
#Also I'm abusing the fact that if you give Graphite a unix timestamp of 0 then it just straight up drops the metric.
import os
import sys
import time
import json
from subprocess import Popen,PIPE
from socket import socket
CARBON_SERVER='192.168.1.1'
CARBON_PORT=2003
sock = socket()
try:
sock.connect( (CARBON_SERVER,CARBON_PORT) )
except:
print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
#sys.exit(1)
now = int( time.time() )
now = str(now)
lines = []
p1 = Popen(["/usr/bin/isi","status"], stdout=PIPE)
p2 = Popen(["awk","/Cluster Name/{print $3}"], stdin=p1.stdout, stdout=PIPE)
clustername = p2.communicate()[0]
clustername = clustername.rstrip("\n\r")
#From a previously generated quota report "isi quota quotas ls --path /ifs --recurse-path-children --format json > quota_list.json"
#p1=open('quota_list.json').read()
p1 = Popen(["/usr/bin/isi","quota","quotas","list","--format","json","--type","directory"], stdout=PIPE).communicate()[0]
for node in json.loads(p1):
id = node.get('type')
if id == 'directory':
hard = node.get('thresholds').get('hard')
if hard is not None:
hard
else:
hard = 0
hard_percent = hard + 1
path = node.get('path').replace("/",".")
used_l = node.get('usage').get('logical',0)
used_p = node.get('usage').get('physical',0)
inodes = node.get('usage').get('inodes')
hard_exceeded_ts = node.get('thresholds').get('hard_last_exceeded')
if hard_exceeded_ts is None:
hard_exceeded_ts = 0
hard_exceeded = node.get('thresholds').get('hard_exceeded')
if hard_exceeded is True:
hard_exceeded = 1
else:
hard_exceeded = 0
protection_overhead_float = 100 * float(used_l)/float(used_p)
protection_overhead = "%.2f" % protection_overhead_float
percentage_float = 100 * float(used_l)/float(hard_percent)
percentage_ts = now
if percentage_float < 101:
percentage_float
else:
percentage_float = 0
percentage_ts = str(0)
percentage = "%.2f" % percentage_float
lines.append("isilon_directory_quotas." + clustername + path + ".hard" + " " + str(hard) + " " + now)
lines.append("isilon_directory_quotas." + clustername + path + ".used_l" + " " + str(used_l) + " " + now)
lines.append("isilon_directory_quotas." + clustername + path + ".used_p" + " " + str(used_p) + " " + now)
lines.append("isilon_directory_quotas." + clustername + path + ".inodes" + " " + str(inodes) + " " + now)
lines.append("isilon_directory_quotas." + clustername + path + ".hard_exceeded" + " " + str(hard_exceeded) + " " + str(hard_exceeded_ts))
lines.append("isilon_directory_quotas." + clustername + path + ".percentage" + " " + str(percentage) + " " + percentage_ts)
lines.append("isilon_directory_quotas." + clustername + path + ".protection_overhead" + " " + str(protection_overhead) + " " + now)
message = '\n'.join(lines) + '\n'
sock.sendall(message)
#Testing appended output
#print message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment