Permalink
Browse files

Merge branch 'master' of https://github.com/ganglia/gmond_python_modules

  • Loading branch information...
vuksan
vuksan committed Jul 5, 2012
2 parents 936936d + b4649cb commit 6777c54af7aaebfb2293541a8e5b93c37ff91380
Showing with 72 additions and 21 deletions.
  1. +8 −0 nfsstats/conf.d/nfsstats.pyconf
  2. +38 −3 nfsstats/python_modules/nfsstats.py
  3. +26 −18 rabbit/python_modules/rabbitmq.py
@@ -8,6 +8,10 @@ modules {
collection_group {
collect_every = 60
time_threshold = 120
+ metric {
+ name = "nfs_v3_total"
+ title = "NFS v3 total"
+ }
metric {
name = "nfs_v3_getattr"
title = "NFS v3 getattr"
@@ -92,6 +96,10 @@ collection_group {
name = "nfs_v3_commit"
title = "NFS v3 commit"
}
+ metric {
+ name = "nfsd_v3_total"
+ title = "NFSD v3 total"
+ }
metric {
name = "nfsd_v3_getattr"
title = "NFSD v3 getattr"
@@ -6,6 +6,26 @@
import time
import syslog
import sys
+import string
+
+def test_proc3( p_file ):
+
+ """
+ Check if <p_file> contains keyword 'proc3'
+ """
+
+ p_fd = open( p_file )
+
+ p_contents = p_fd.read()
+
+ p_fd.close()
+
+ m = re.search(".*proc3.*", p_contents, flags=re.MULTILINE)
+
+ if not m:
+ return False
+ else:
+ return True
verboselevel = 0
descriptors = [ ]
@@ -14,14 +34,15 @@
configtable = [
{
'group': 'nfs_client',
- 'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfs").st_mode)' ],
+ 'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfs").st_mode)', 'test_proc3("/proc/net/rpc/nfs")' ],
'prefix': 'nfs_v3_',
# The next 4 lines can be at the 'group' level or the 'name' level
'file': '/proc/net/rpc/nfs',
'value_type': 'float',
'units': 'calls/sec',
'format': '%f',
'names': {
+ 'total': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\d+.*\d)\n" },
'getattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\S*)" },
'setattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){3}(\S*)" },
'lookup': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){4}(\S*)" },
@@ -47,14 +68,15 @@
},
{
'group': 'nfs_server',
- 'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfsd").st_mode)' ],
+ 'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfsd").st_mode)', 'test_proc3("/proc/net/rpc/nfsd")' ],
'prefix': 'nfsd_v3_',
# The next 4 lines can be at the 'group' level or the 'name' level
'file': '/proc/net/rpc/nfsd',
'value_type': 'float',
'units': 'calls/sec',
'format': '%f',
'names': {
+ 'total': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\d+.*\d)\n" },
'getattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\S*)" },
'setattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){3}(\S*)" },
'lookup': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){4}(\S*)" },
@@ -178,10 +200,23 @@ def get_value(name):
break
contents = file(descriptors[i]['file']).read()
m = re.search(descriptors[i]['re'], contents, flags=re.MULTILINE)
+
+ m_value = m.group(1)
+
+ #RB: multiple (space seperated) values: calculate sum
+ if string.count( m_value, ' ' ) > 0:
+ m_fields = string.split( m_value, ' ' )
+
+ sum_value = 0
+
+ for f in m_fields:
+ sum_value = sum_value + int(f)
+
+ m_value = sum_value
# Return time and value.
ts = time.time()
- return (ts, int(m.group(1)))
+ return (ts, int(m_value))
def debug(level, text):
global verboselevel
@@ -65,10 +65,10 @@ def metric_cleanup():
def dig_it_up(obj,path):
try:
- if type(path) in (str,unicode):
- path = path.split('.')
+ path = path.split('.')
return reduce(lambda x,y:x[y],path,obj)
except:
+ print "Exception"
return False
def refreshGroup(group):
@@ -123,42 +123,47 @@ def list_nodes():
return results.keys()
def getQueueStat(name):
- #Split a name like "rmq_backing_queue_ack_egress_rate-access"
- stat_name, queue_name = name.split(".")
-
+ #Split a name like "rmq_backing_queue_ack_egress_rate.access"
+
+ #handle queue names with . in them
+ split_name = name.split(".")
+ stat_name = split_name[0]
+ queue_name = ".".join(split_name[1:])
+
result = refreshGroup('queues')
value = dig_it_up(result, keyToPath[stat_name] % queue_name)
+ print name, value
#Convert Booleans
if value is True:
value = 1
elif value is False:
value = 0
- return value
+ return float(value)
def getNodeStat(name):
- #Split a name like "rmq_backing_queue_ack_egress_rate-access"
- stat_name, node_name = name.split(".")
-
+ #Split a name like "rmq_backing_queue_ack_egress_rate.access"
+ stat_name, node_name = name.split(".")
result = refreshGroup('nodes')
-
value = dig_it_up(result, keyToPath[stat_name] % node_name)
-
+ print name,value
#Convert Booleans
if value is True:
value = 1
elif value is False:
value = 0
- return value
+ return float(value)
def metric_init(params):
''' Create the metric definition object '''
global descriptors, stats, vhost, username, password, urlstring, url_template, compiled_results
print 'received the following params:'
#Set this globally so we can refresh stats
+ if 'host' not in params:
+ params['host'], params['vhost'],params['username'],params['password'] = "localhost", "/", "guest", "guest"
vhost = params['vhost']
username, password = params['username'], params['password']
host = params['host']
@@ -198,15 +203,15 @@ def buildQueueDescriptors():
'value_type': 'float',
'units': 'N',
'slope': 'both',
- 'format': '%d',
+ 'format': '%f',
'description': 'Queue_Metric',
'groups' : 'rabbitmq,queue'})
-
+ print d1
descriptors.append(d1)
def buildNodeDescriptors():
for node in list_nodes():
- node = node.split('@')[0]
+ #node = node.split('@')[0]
for stat in NODE_METRICS:
name = '%s.%s' % (stat, node)
print name
@@ -215,7 +220,7 @@ def buildNodeDescriptors():
'value_type': 'float',
'units': 'N',
'slope': 'both',
- 'format': '%d',
+ 'format': '%f',
'description': 'Node_Metric',
'groups' : 'rabbitmq,node'})
print d2
@@ -237,5 +242,8 @@ def metric_cleanup():
parameters = {"vhost":"/", "username":"guest","password":"guest", "metric_group":"rabbitmq"}
metric_init(parameters)
result = refreshGroup('queues')
- print dig_it_up(result, 'clientlog.backing_queue_status.avg_egress_rate')
-
+ node_result = refreshGroup('nodes')
+ print '***'*10
+ getQueueStat('rmq_backing_queue_ack_egress_rate.gelf_client_three')
+ getNodeStat('rmq_disk_free.rmqtwo@inrmq02d1')
+ getNodeStat('rmq_mem_used.rmqtwo@inrmq02d1')

0 comments on commit 6777c54

Please sign in to comment.