Skip to content

Instantly share code, notes, and snippets.

@scr512
Last active December 23, 2015 07:28
Show Gist options
  • Save scr512/6600708 to your computer and use it in GitHub Desktop.
Save scr512/6600708 to your computer and use it in GitHub Desktop.
Exports Isilon directory quota information as XML, parses through it and sends the data to Graphite.
#!/usr/bin/env/python
# Version: 2.0
# Author: Jason Davis
# Date: 11/2/2014
# Changes:
# Replacing "/" with "_" as a delimiter was kinda a bad idea. Using "." which is more standard with Graphite metric naming.
# That last logic change was kinda crudely implemented. We shouldn't assume that each quota has a hard threshold and assign a value of 0.
# Added some logic to account for "NoneType" hard thresholds. This is typically seen in quotas being impelemented for accounting purposes only.
# Purpose: Send Isilon directory quota usage details to Graphite for visualization
# Notes:
# This was inspired by the work of "tghartmann" https://github.com/tjhartmann/ilmn_scripts/blob/master/graphite/ifs_quotas.py
# This in intended to be executed on single node in cluster via cron. Tested with OneFS 6.5.5.x.
# This should also work on OneFS 7.x with slight modification of the isi quota command.
# From "isi quota get --export" To "isi quota quotas get --export" (I think, don't have OneFS 7.x in front of me at present!)
import os
import sys
import time
from subprocess import Popen,PIPE
from socket import socket
from xml.etree import cElementTree
# Carbon
CARBON_SERVER='10.112.81.144'
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)
# Graphite time (Using a bit of TJ's code here)
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") # chomp
# Parsin' some XML
#From a previously generated quota report "isi quota get --export > quota_list.xml"
#with open('quota_list.xml', 'rt') as f:
# tree = cElementTree.parse(f)
p1 = Popen(["/usr/bin/isi_classic","quota","get","--directory","--export"], stdout=PIPE).communicate()[0]
tree = cElementTree.fromstring(p1)
for node in tree.getiterator():
id = node.get('type')
if id == 'ALL':
hard = node.find('.//enforcement/*')
if hard is not None:
hard = hard.text
lines.append("isilon_directory_quotas." + clustername + path + ".hard" + " " + str(hard) + " " + now)
else:
hard = hard = ''
lines.append("isilon_directory_quotas." + clustername + path + ".nohard" + " " + str(hard) + " " + now)
path = node.find('path').text.replace("/",".")
usage_l = node.getiterator('usage')
for usage_l in usage_l:
logical = usage_l.get('resource')
if logical == 'logical':
used_l = usage_l.text
usage_p = node.getiterator('usage')
for usage_p in usage_p:
physical = usage_p.get('resource')
if physical == 'physical':
used_p = usage_p.text
#Format output and send on over to Graphite (Using a bit of TJ's code here)
lines.append("isilon_directory_quotas." + clustername + path + ".used_l" + " " + used_l+ " " + now)
lines.append("isilon_directory_quotas." + clustername + path + ".used_p" + " " + used_p + " " + 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