From 2b6faa673221f8b2ea5ab17d955067d5ac1f2b2d Mon Sep 17 00:00:00 2001 From: Xupeng Yun Date: Thu, 31 Mar 2011 05:53:51 +0200 Subject: [PATCH] Initial version --- plugins/other/sockstat-via-procfs | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 plugins/other/sockstat-via-procfs diff --git a/plugins/other/sockstat-via-procfs b/plugins/other/sockstat-via-procfs new file mode 100755 index 00000000..4c875aa2 --- /dev/null +++ b/plugins/other/sockstat-via-procfs @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import re +import sys + +fields = ( + ('sockets_used', 'sockets used'), + ('tcp_inuse', 'TCP inuse'), + ('tcp_orphan', 'TCP orphan'), + ('tcp_tw', 'TCP tw'), + ('tcp_alloc', 'TCP alloc'), + ('tcp_mem', 'TCP mem'), + ('udp_inuse', 'UDP inuse'), + ('udplite_inuse', 'UDPLITE inuse'), + ('raw_inuse', 'RAW inuse'), + ('frag_inuse', 'FRAG inuse'), + ('frag_memory', 'FRAG memory'), +) + +if len(sys.argv) > 1: + arg = sys.argv[1] + if arg == 'autoconfig': + print 'yes' + sys.exit(0) + if arg == 'config': + print 'graph_title sockstat' + print 'graph_category network' + for name, label in fields: + print '%s.label %s' % (name, label) + sys.exit(0) + +re_num = re.compile('(\d+)') +sockstat = open('/proc/net/sockstat').read() +numbers = re_num.findall(sockstat) + +for i, (name, label) in enumerate(fields): + print '%s.value %s' % (name, numbers[i]) + +sys.exit(0)