Révision c00f7af9
Revert "python3 dependency fixed (backport)"
| plugins/time/ntp_packets | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 1 |
#!/usr/bin/env python3
|
|
| 2 | 2 |
# -*- python -*- |
| 3 | 3 |
|
| 4 | 4 |
# This plugin graphs the rate of sent, received, ignored, and dropped |
| ... | ... | |
| 13 | 13 |
# Symlink this plugin into the node's plugins directory (like |
| 14 | 14 |
# /etc/munin/plugins). |
| 15 | 15 |
# |
| 16 |
# Copyright [c] 2013 Kenyon Ralph <kenyon@kenyonralph.com>
|
|
| 16 |
# Copyright © 2013 Kenyon Ralph <kenyon@kenyonralph.com>
|
|
| 17 | 17 |
# |
| 18 | 18 |
# This program is free software. It comes without any warranty, to the |
| 19 | 19 |
# extent permitted by applicable law. You can redistribute it and/or |
| ... | ... | |
| 31 | 31 |
import subprocess |
| 32 | 32 |
import sys |
| 33 | 33 |
|
| 34 |
if len(sys.argv) == 2 and sys.argv[1] == u'config':
|
|
| 35 |
print u'graph_title NTP packets'
|
|
| 36 |
print u'graph_vlabel Packets/${graph_period} received(-)/sent(+)'
|
|
| 37 |
print u'graph_info This graph shows the packet rates of this ntpd. Ignored and dropped packets are graphed as positive values.'
|
|
| 38 |
print u'graph_category time'
|
|
| 39 |
print u'received.label Received'
|
|
| 40 |
print u'received.type DERIVE'
|
|
| 41 |
print u'received.graph no'
|
|
| 42 |
print u'received.min 0'
|
|
| 43 |
print u'sent.label Rx/Tx'
|
|
| 44 |
print u'sent.type DERIVE'
|
|
| 45 |
print u'sent.negative received'
|
|
| 46 |
print u'sent.min 0'
|
|
| 47 |
print u'dropped.label Dropped'
|
|
| 48 |
print u'dropped.type DERIVE'
|
|
| 49 |
print u'dropped.min 0'
|
|
| 50 |
print u'ignored.label Ignored'
|
|
| 51 |
print u'ignored.type DERIVE'
|
|
| 52 |
print u'ignored.min 0'
|
|
| 34 |
if len(sys.argv) == 2 and sys.argv[1] == 'config': |
|
| 35 |
print('graph_title NTP traffic')
|
|
| 36 |
print('graph_vlabel Packets/${graph_period} received(-)/sent(+)')
|
|
| 37 |
print('graph_info This graph shows the packet rates of this ntpd. Ignored and dropped packets are graphed as positive values.')
|
|
| 38 |
print('graph_category time')
|
|
| 39 |
print('received.label Received')
|
|
| 40 |
print('received.type DERIVE')
|
|
| 41 |
print('received.graph no')
|
|
| 42 |
print('received.min 0')
|
|
| 43 |
print('sent.label Rx/Tx')
|
|
| 44 |
print('sent.type DERIVE')
|
|
| 45 |
print('sent.negative received')
|
|
| 46 |
print('sent.min 0')
|
|
| 47 |
print('dropped.label Dropped')
|
|
| 48 |
print('dropped.type DERIVE')
|
|
| 49 |
print('dropped.min 0')
|
|
| 50 |
print('ignored.label Ignored')
|
|
| 51 |
print('ignored.type DERIVE')
|
|
| 52 |
print('ignored.min 0')
|
|
| 53 | 53 |
sys.exit(0) |
| 54 | 54 |
|
| 55 |
os.environ[u'PATH'] = u'/usr/local/sbin:/usr/local/bin:' + os.environ[u'PATH']
|
|
| 55 |
os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:' + os.environ['PATH']
|
|
| 56 | 56 |
|
| 57 | 57 |
# Assuming that the ntpd version is the same as the ntpq or ntpdc |
| 58 | 58 |
# version. This is how a proper install should be. |
| 59 | 59 |
|
| 60 |
version = subprocess.check_output([u'ntpq', u'-c', u'version'], universal_newlines=True).split()[1][0:5].replace(u'.', u'')
|
|
| 60 |
version = subprocess.check_output(['ntpq', '-c', 'version'], universal_newlines=True).split()[1][0:5].replace('.', '')
|
|
| 61 | 61 |
|
| 62 | 62 |
if int(version) >= 427: |
| 63 |
cmd = u'ntpq'
|
|
| 63 |
cmd = 'ntpq' |
|
| 64 | 64 |
else: |
| 65 |
cmd = u'ntpdc'
|
|
| 65 |
cmd = 'ntpdc' |
|
| 66 | 66 |
|
| 67 | 67 |
iostats = dict() |
| 68 | 68 |
|
| 69 |
iostats_output = subprocess.check_output([cmd, u'-c', u'iostats'], universal_newlines=True).splitlines()
|
|
| 69 |
iostats_output = subprocess.check_output([cmd, '-c', 'iostats'], universal_newlines=True).splitlines()
|
|
| 70 | 70 |
|
| 71 |
for line in iostats_output: iostats[line.split(u':')[0]] = int(line.split(u':')[1])
|
|
| 71 |
for line in iostats_output: iostats[line.split(':')[0]] = int(line.split(':')[1])
|
|
| 72 | 72 |
|
| 73 |
print u'received.value ' + unicode(iostats[u'received packets'])
|
|
| 74 |
print u'sent.value ' + unicode(iostats[u'packets sent'])
|
|
| 75 |
print u'dropped.value ' + unicode(iostats[u'dropped packets'])
|
|
| 76 |
print u'ignored.value ' + unicode(iostats[u'ignored packets'])
|
|
| 73 |
print('received.value ' + str(iostats['received packets']))
|
|
| 74 |
print('sent.value ' + str(iostats['packets sent']))
|
|
| 75 |
print('dropped.value ' + str(iostats['dropped packets']))
|
|
| 76 |
print('ignored.value ' + str(iostats['ignored packets']))
|
|
| 77 | 77 |
|
| 78 | 78 |
sys.exit(0) |
Formats disponibles : Unified diff