-
Notifications
You must be signed in to change notification settings - Fork 1
/
nfs_stats.py
executable file
·70 lines (52 loc) · 1.65 KB
/
nfs_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# Collectd
# Facundo Guerrero < [email protected] >
# FreeBSD cacti NFS stats parser
import os
import collectd
STATS_FILE = '/tmp/nfs_stats_output_collectd'
def generate_stats():
nfs_command = '/usr/bin/nfsstat -s|/usr/bin/head -n8 |/usr/bin/tail -n6'
stats_file = open(STATS_FILE, "w")
stats = os.popen(nfs_command)
stats_file.write(stats.read())
stats_file.close()
def clean():
os.remove(STATS_FILE)
def read(data=None):
generate_stats()
f = open(STATS_FILE, "ro")
a = dict()
while True:
line1 = f.readline().split()
line2 = f.readline().split()
if not line2:
break
i = 0
for x in line1:
a[line1[i]] = int(line2[i])
i = i + 1
f.close()
send_stats(a)
clean()
def send_stats(data=None):
order = ("Getattr Setattr Lookup Access Readlink Read Write Create Mkdir Symlink Mknod Remove Rmdir Rename Link Readdir RdirPlus Fsstat Fsinfo PathConf Commit")
for x in order.split():
dispatch_stat(data[x], x.lower())
def dispatch_stat(value, name):
"""Read a key from info response data and dispatch a value"""
if value is None:
collectd.warning('nfs plugin: Value not found for %s' % name)
return
if value < 0:
collectd.warning('nfs plugin: Value is negative for %s' % name)
value = 0
collectd.info('Sending value[counter]: %s=%s' % (name, value))
val = collectd.Values(plugin='nfs')
val.type = 'counter'
val.type_instance = name
val.values = [value]
#print val
val.dispatch()
collectd.register_read(read)
collectd.register_shutdown(clean)