Skip to content

Instantly share code, notes, and snippets.

@scr512
Created July 30, 2019 19:27
Show Gist options
  • Save scr512/b490be7b25d165c6407972230117a03c to your computer and use it in GitHub Desktop.
Save scr512/b490be7b25d165c6407972230117a03c to your computer and use it in GitHub Desktop.
Send Isilon directory quota usage details to Graphite for visualization
#!/usr/bin/env/python
# Version: 2.3.1
# Author: Jason Davis
# Date: 08/09/2018
# Purpose: Send Isilon directory quota usage details to Graphite for visualization
#----------------------------------------------------------------------------------------------------------------------------------------------
# Changes:
# Setup to grab user quotas
# 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.
# Removed else statment that replaced blank usernames with "unknown" as this is very confusing to end-users
# Removed specific queries looking for Arm specific sub directories under /ifs. Rather, we just grab anything under /ifs.
# Printing all variable as strings as certain clusters seem to have "strange" characters in username and/or file path.
import os
import sys
import time
from subprocess import Popen,PIPE
from socket import socket
from xml.etree import cElementTree
# Carbon (Graphite)
CARBON_SERVER='192.168.1.100'
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") # 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)
#Just looking at /ifs
p1 = Popen(["/usr/bin/isi_classic","quota","get","--recurse-path=/ifs","--export"], stdout=PIPE).communicate()[0]
tree = cElementTree.fromstring(p1)
for node in tree.getiterator():
id = node.get('type')
if id == 'user':
path = node.find('path').text.replace("/",".")
user = node.find('id-name').text
if user is not None:
user = user.replace("USA\\","")
user = user.replace("ARM\\","")
user = user.replace("EMEA\\","")
user = user.replace("ASIAPAC\\","")
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
inodes = node.getiterator('usage')
for inodes in inodes:
inodes_count = inodes.get('resource')
if inodes_count == 'inodes':
inodes = inodes.text
lines.append("isilon_user_quotas." + str(clustername) + "." + str(user) + str(path) + ".used_l" + " " + str(used_l) + " " + now)
lines.append("isilon_user_quotas." + str(clustername) + "." + str(user) + str(path) + ".used_p" + " " + str(used_p) + " " + now)
lines.append("isilon_user_quotas." + str(clustername) + "." + str(user) + str(path) + ".inodes" + " " + str(inodes) + " " + 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