Created
August 7, 2013 20:19
-
-
Save scr512/6178204 to your computer and use it in GitHub Desktop.
Send Isilon user quota data to Graphite
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
#!/usr/bin/env python | |
# Title: send_user_quota_to_carbon.py | |
# Version: 1.0 | |
# Author: Jason Davis | |
# Date: 08/07/2013 | |
# Purpose: Send Isilon user quota usage details to Graphite for visualization | |
# Notes: | |
# This was inspired by the work of "tjhartmann" 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.10.138' | |
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","quota","get","--export"], stdout=PIPE).communicate()[0] | |
tree = cElementTree.fromstring(p1) | |
for node in tree.getiterator(): | |
id = node.get('type') | |
if id == 'user': | |
hard = node.find('.//enforcement/*').text | |
user = node.find('id-name').text | |
if user is not None: | |
user | |
else: | |
user = 'unknown' | |
path = node.find('path').text.replace("/","_") | |
usage = node.getiterator('usage') | |
for usage in usage: | |
logical = usage.get('resource') | |
if logical == 'logical': | |
used = usage.text | |
# Format output and send on over to Graphite (Using a bit of TJ's code here) | |
lines.append("isilon_user_quotas." + clustername + "." + user + "." + path + ".hard" + " " + hard + " " + now) | |
lines.append("isilon_user_quotas." + clustername + "." + user + "." + path + ".used" + " " + used + " " + 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