Skip to content
This repository was archived by the owner on Jun 22, 2022. It is now read-only.

Commit 6777c54

Browse files
committed
2 parents 936936d + b4649cb commit 6777c54

3 files changed

Lines changed: 72 additions & 21 deletions

File tree

nfsstats/conf.d/nfsstats.pyconf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ modules {
88
collection_group {
99
collect_every = 60
1010
time_threshold = 120
11+
metric {
12+
name = "nfs_v3_total"
13+
title = "NFS v3 total"
14+
}
1115
metric {
1216
name = "nfs_v3_getattr"
1317
title = "NFS v3 getattr"
@@ -92,6 +96,10 @@ collection_group {
9296
name = "nfs_v3_commit"
9397
title = "NFS v3 commit"
9498
}
99+
metric {
100+
name = "nfsd_v3_total"
101+
title = "NFSD v3 total"
102+
}
95103
metric {
96104
name = "nfsd_v3_getattr"
97105
title = "NFSD v3 getattr"

nfsstats/python_modules/nfsstats.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66
import time
77
import syslog
88
import sys
9+
import string
10+
11+
def test_proc3( p_file ):
12+
13+
"""
14+
Check if <p_file> contains keyword 'proc3'
15+
"""
16+
17+
p_fd = open( p_file )
18+
19+
p_contents = p_fd.read()
20+
21+
p_fd.close()
22+
23+
m = re.search(".*proc3.*", p_contents, flags=re.MULTILINE)
24+
25+
if not m:
26+
return False
27+
else:
28+
return True
929

1030
verboselevel = 0
1131
descriptors = [ ]
@@ -14,14 +34,15 @@
1434
configtable = [
1535
{
1636
'group': 'nfs_client',
17-
'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfs").st_mode)' ],
37+
'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfs").st_mode)', 'test_proc3("/proc/net/rpc/nfs")' ],
1838
'prefix': 'nfs_v3_',
1939
# The next 4 lines can be at the 'group' level or the 'name' level
2040
'file': '/proc/net/rpc/nfs',
2141
'value_type': 'float',
2242
'units': 'calls/sec',
2343
'format': '%f',
2444
'names': {
45+
'total': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\d+.*\d)\n" },
2546
'getattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\S*)" },
2647
'setattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){3}(\S*)" },
2748
'lookup': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){4}(\S*)" },
@@ -47,14 +68,15 @@
4768
},
4869
{
4970
'group': 'nfs_server',
50-
'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfsd").st_mode)' ],
71+
'tests': [ 'stat.S_ISREG(os.stat("/proc/net/rpc/nfsd").st_mode)', 'test_proc3("/proc/net/rpc/nfsd")' ],
5172
'prefix': 'nfsd_v3_',
5273
# The next 4 lines can be at the 'group' level or the 'name' level
5374
'file': '/proc/net/rpc/nfsd',
5475
'value_type': 'float',
5576
'units': 'calls/sec',
5677
'format': '%f',
5778
'names': {
79+
'total': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\d+.*\d)\n" },
5880
'getattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){2}(\S*)" },
5981
'setattr': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){3}(\S*)" },
6082
'lookup': { 'description':'dummy description', 're': ".*proc3 (?:\S*\s){4}(\S*)" },
@@ -178,10 +200,23 @@ def get_value(name):
178200
break
179201
contents = file(descriptors[i]['file']).read()
180202
m = re.search(descriptors[i]['re'], contents, flags=re.MULTILINE)
203+
204+
m_value = m.group(1)
205+
206+
#RB: multiple (space seperated) values: calculate sum
207+
if string.count( m_value, ' ' ) > 0:
208+
m_fields = string.split( m_value, ' ' )
209+
210+
sum_value = 0
211+
212+
for f in m_fields:
213+
sum_value = sum_value + int(f)
214+
215+
m_value = sum_value
181216

182217
# Return time and value.
183218
ts = time.time()
184-
return (ts, int(m.group(1)))
219+
return (ts, int(m_value))
185220

186221
def debug(level, text):
187222
global verboselevel

rabbit/python_modules/rabbitmq.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def metric_cleanup():
6565

6666
def dig_it_up(obj,path):
6767
try:
68-
if type(path) in (str,unicode):
69-
path = path.split('.')
68+
path = path.split('.')
7069
return reduce(lambda x,y:x[y],path,obj)
7170
except:
71+
print "Exception"
7272
return False
7373

7474
def refreshGroup(group):
@@ -123,42 +123,47 @@ def list_nodes():
123123
return results.keys()
124124

125125
def getQueueStat(name):
126-
#Split a name like "rmq_backing_queue_ack_egress_rate-access"
127-
stat_name, queue_name = name.split(".")
128-
126+
#Split a name like "rmq_backing_queue_ack_egress_rate.access"
127+
128+
#handle queue names with . in them
129+
split_name = name.split(".")
130+
stat_name = split_name[0]
131+
queue_name = ".".join(split_name[1:])
132+
129133
result = refreshGroup('queues')
130134

131135
value = dig_it_up(result, keyToPath[stat_name] % queue_name)
136+
print name, value
132137

133138
#Convert Booleans
134139
if value is True:
135140
value = 1
136141
elif value is False:
137142
value = 0
138143

139-
return value
144+
return float(value)
140145

141146
def getNodeStat(name):
142-
#Split a name like "rmq_backing_queue_ack_egress_rate-access"
143-
stat_name, node_name = name.split(".")
144-
147+
#Split a name like "rmq_backing_queue_ack_egress_rate.access"
148+
stat_name, node_name = name.split(".")
145149
result = refreshGroup('nodes')
146-
147150
value = dig_it_up(result, keyToPath[stat_name] % node_name)
148-
151+
print name,value
149152
#Convert Booleans
150153
if value is True:
151154
value = 1
152155
elif value is False:
153156
value = 0
154157

155-
return value
158+
return float(value)
156159

157160
def metric_init(params):
158161
''' Create the metric definition object '''
159162
global descriptors, stats, vhost, username, password, urlstring, url_template, compiled_results
160163
print 'received the following params:'
161164
#Set this globally so we can refresh stats
165+
if 'host' not in params:
166+
params['host'], params['vhost'],params['username'],params['password'] = "localhost", "/", "guest", "guest"
162167
vhost = params['vhost']
163168
username, password = params['username'], params['password']
164169
host = params['host']
@@ -198,15 +203,15 @@ def buildQueueDescriptors():
198203
'value_type': 'float',
199204
'units': 'N',
200205
'slope': 'both',
201-
'format': '%d',
206+
'format': '%f',
202207
'description': 'Queue_Metric',
203208
'groups' : 'rabbitmq,queue'})
204-
209+
print d1
205210
descriptors.append(d1)
206211

207212
def buildNodeDescriptors():
208213
for node in list_nodes():
209-
node = node.split('@')[0]
214+
#node = node.split('@')[0]
210215
for stat in NODE_METRICS:
211216
name = '%s.%s' % (stat, node)
212217
print name
@@ -215,7 +220,7 @@ def buildNodeDescriptors():
215220
'value_type': 'float',
216221
'units': 'N',
217222
'slope': 'both',
218-
'format': '%d',
223+
'format': '%f',
219224
'description': 'Node_Metric',
220225
'groups' : 'rabbitmq,node'})
221226
print d2
@@ -237,5 +242,8 @@ def metric_cleanup():
237242
parameters = {"vhost":"/", "username":"guest","password":"guest", "metric_group":"rabbitmq"}
238243
metric_init(parameters)
239244
result = refreshGroup('queues')
240-
print dig_it_up(result, 'clientlog.backing_queue_status.avg_egress_rate')
241-
245+
node_result = refreshGroup('nodes')
246+
print '***'*10
247+
getQueueStat('rmq_backing_queue_ack_egress_rate.gelf_client_three')
248+
getNodeStat('rmq_disk_free.rmqtwo@inrmq02d1')
249+
getNodeStat('rmq_mem_used.rmqtwo@inrmq02d1')

0 commit comments

Comments
 (0)