Created
September 15, 2011 20:09
-
-
Save hgdeoro/1220331 to your computer and use it in GitHub Desktop.
Munin plugin for monitoring Squid use of file descriptors
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/python | |
import os | |
import re | |
import sys | |
from subprocess import Popen, PIPE | |
def main(): | |
output = Popen(["squidclient", "mgr:info"], stdout=PIPE).communicate()[0] | |
output = [x.strip() for x in output.splitlines()] | |
if len(sys.argv) == 1: | |
data = {} | |
for line in output: | |
k = line.split(':')[0] | |
v = ':'.join(line.split(':')[1:]) | |
data[k.strip()] = v.strip() | |
if os.environ.get('DUMPDATA', False): | |
print data | |
max_fd = data.get('Maximum number of file descriptors', '-1') | |
largest_fd = data.get('Largest file desc currently in use', '-1') | |
inuse_fd = data.get('Number of file desc currently in use', '-1') | |
queued_fd = data.get('Files queued for open', '-1') | |
print "max_fd.value %s" % max_fd | |
print "largest_fd.value %s" % largest_fd | |
print "inuse_fd.value %s" % inuse_fd | |
print "queued_fd.value %s" % queued_fd | |
sys.exit(0) | |
else: | |
if sys.argv[1] == 'config': | |
# File descriptor usage for squid: | |
# Maximum number of file descriptors: 4096 | |
# Largest file desc currently in use: 1082 | |
# Number of file desc currently in use: 913 | |
# Files queued for open: 0 | |
print "graph_title Squid file descriptors" | |
print "graph_category squid" | |
print "graph_args --base 1000" | |
print "graph_vlabel number of fd" | |
print "graph_order max_fd largest_fd inuse_fd queued_fd" | |
print "max_fd.label Max. number of fd" | |
print "max_fd.colour 0000ff" | |
print "largest_fd.label Largest fd in use" | |
print "largest_fd.colour ff0000" | |
print "inuse_fd.label Currently fd in use" | |
print "inuse_fd.colour 00ff00" | |
print "queued_fd.label Queued fd for open" | |
print "queued_fd.colour 000000" | |
else: | |
print "ERROR: debe ejecutarse sin parametros, o con 'config'" | |
sys.exit(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment