1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-26 02:48:28 +00:00

backported to work with python 2.7.10

https://wiki.python.org/moin/3to2
This commit is contained in:
Sarah White 2016-02-25 04:13:46 -05:00
parent 1733fee7f8
commit 415d952525

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
# -*- python -*- # -*- python -*-
# This plugin graphs the rate of sent, received, ignored, and dropped # This plugin graphs the rate of sent, received, ignored, and dropped
@ -31,48 +31,48 @@ import os
import subprocess import subprocess
import sys import sys
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == u'config':
print('graph_title NTP packets') print u'graph_title NTP packets'
print('graph_vlabel Packets/${graph_period} received(-)/sent(+)') print u'graph_vlabel Packets/${graph_period} received(-)/sent(+)'
print('graph_info This graph shows the packet rates of this ntpd. Ignored and dropped packets are graphed as positive values.') print u'graph_info This graph shows the packet rates of this ntpd. Ignored and dropped packets are graphed as positive values.'
print('graph_category time') print u'graph_category time'
print('received.label Received') print u'received.label Received'
print('received.type DERIVE') print u'received.type DERIVE'
print('received.graph no') print u'received.graph no'
print('received.min 0') print u'received.min 0'
print('sent.label Rx/Tx') print u'sent.label Rx/Tx'
print('sent.type DERIVE') print u'sent.type DERIVE'
print('sent.negative received') print u'sent.negative received'
print('sent.min 0') print u'sent.min 0'
print('dropped.label Dropped') print u'dropped.label Dropped'
print('dropped.type DERIVE') print u'dropped.type DERIVE'
print('dropped.min 0') print u'dropped.min 0'
print('ignored.label Ignored') print u'ignored.label Ignored'
print('ignored.type DERIVE') print u'ignored.type DERIVE'
print('ignored.min 0') print u'ignored.min 0'
sys.exit(0) sys.exit(0)
os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:' + os.environ['PATH'] os.environ[u'PATH'] = u'/usr/local/sbin:/usr/local/bin:' + os.environ[u'PATH']
# Assuming that the ntpd version is the same as the ntpq or ntpdc # Assuming that the ntpd version is the same as the ntpq or ntpdc
# version. This is how a proper install should be. # version. This is how a proper install should be.
version = subprocess.check_output(['ntpq', '-c', 'version'], universal_newlines=True).split()[1][0:5].replace('.', '') version = subprocess.check_output([u'ntpq', u'-c', u'version'], universal_newlines=True).split()[1][0:5].replace(u'.', u'')
if int(version) >= 427: if int(version) >= 427:
cmd = 'ntpq' cmd = u'ntpq'
else: else:
cmd = 'ntpdc' cmd = u'ntpdc'
iostats = dict() iostats = dict()
iostats_output = subprocess.check_output([cmd, '-c', 'iostats'], universal_newlines=True).splitlines() iostats_output = subprocess.check_output([cmd, u'-c', u'iostats'], universal_newlines=True).splitlines()
for line in iostats_output: iostats[line.split(':')[0]] = int(line.split(':')[1]) for line in iostats_output: iostats[line.split(u':')[0]] = int(line.split(u':')[1])
print('received.value ' + str(iostats['received packets'])) print u'received.value ' + unicode(iostats[u'received packets'])
print('sent.value ' + str(iostats['packets sent'])) print u'sent.value ' + unicode(iostats[u'packets sent'])
print('dropped.value ' + str(iostats['dropped packets'])) print u'dropped.value ' + unicode(iostats[u'dropped packets'])
print('ignored.value ' + str(iostats['ignored packets'])) print u'ignored.value ' + unicode(iostats[u'ignored packets'])
sys.exit(0) sys.exit(0)