2016-02-25 10:13:46 +01:00
|
|
|
#!/usr/bin/env python
|
2013-03-04 01:14:34 +01:00
|
|
|
# -*- python -*-
|
|
|
|
|
|
|
|
# This plugin graphs the rate of sent, received, ignored, and dropped
|
|
|
|
# NTP packets for an ntpd process. Similarly to the if_ plugins,
|
|
|
|
# received packets are graphed as negative values, and sent packets
|
|
|
|
# are graphed as positive values. Ignored and dropped packets are
|
|
|
|
# graphed as positive values.
|
|
|
|
#
|
|
|
|
# The values are retrieved using ntpq or ntpdc, depending on the
|
|
|
|
# version of the NTP distribution.
|
|
|
|
#
|
|
|
|
# Symlink this plugin into the node's plugins directory (like
|
|
|
|
# /etc/munin/plugins).
|
|
|
|
#
|
2016-02-25 10:22:22 +01:00
|
|
|
# Copyright [c] 2013 Kenyon Ralph <kenyon@kenyonralph.com>
|
2013-03-04 01:14:34 +01:00
|
|
|
#
|
|
|
|
# This program is free software. It comes without any warranty, to the
|
|
|
|
# extent permitted by applicable law. You can redistribute it and/or
|
|
|
|
# modify it under the terms of the Do What The Fuck You Want To Public
|
|
|
|
# License, Version 2, as published by Sam Hocevar. See
|
|
|
|
# http://www.wtfpl.net/ for more details.
|
|
|
|
#
|
|
|
|
# The latest version of this plugin can be found in the munin contrib
|
|
|
|
# repository at https://github.com/munin-monitoring/contrib. Issues
|
|
|
|
# with this plugin may be reported there. Patches accepted through the
|
|
|
|
# normal github process of forking the repository and submitting a
|
|
|
|
# pull request with your commits.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2016-02-25 10:13:46 +01:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == u'config':
|
|
|
|
print u'graph_title NTP packets'
|
|
|
|
print u'graph_vlabel Packets/${graph_period} received(-)/sent(+)'
|
|
|
|
print u'graph_info This graph shows the packet rates of this ntpd. Ignored and dropped packets are graphed as positive values.'
|
|
|
|
print u'graph_category time'
|
|
|
|
print u'received.label Received'
|
|
|
|
print u'received.type DERIVE'
|
|
|
|
print u'received.graph no'
|
|
|
|
print u'received.min 0'
|
|
|
|
print u'sent.label Rx/Tx'
|
|
|
|
print u'sent.type DERIVE'
|
|
|
|
print u'sent.negative received'
|
|
|
|
print u'sent.min 0'
|
|
|
|
print u'dropped.label Dropped'
|
|
|
|
print u'dropped.type DERIVE'
|
|
|
|
print u'dropped.min 0'
|
|
|
|
print u'ignored.label Ignored'
|
|
|
|
print u'ignored.type DERIVE'
|
|
|
|
print u'ignored.min 0'
|
2013-03-04 01:14:34 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2016-02-25 10:13:46 +01:00
|
|
|
os.environ[u'PATH'] = u'/usr/local/sbin:/usr/local/bin:' + os.environ[u'PATH']
|
2013-03-04 01:14:34 +01:00
|
|
|
|
|
|
|
# Assuming that the ntpd version is the same as the ntpq or ntpdc
|
|
|
|
# version. This is how a proper install should be.
|
|
|
|
|
2016-02-25 10:13:46 +01:00
|
|
|
version = subprocess.check_output([u'ntpq', u'-c', u'version'], universal_newlines=True).split()[1][0:5].replace(u'.', u'')
|
2013-03-04 01:14:34 +01:00
|
|
|
|
|
|
|
if int(version) >= 427:
|
2016-02-25 10:13:46 +01:00
|
|
|
cmd = u'ntpq'
|
2013-03-04 01:14:34 +01:00
|
|
|
else:
|
2016-02-25 10:13:46 +01:00
|
|
|
cmd = u'ntpdc'
|
2013-03-04 01:14:34 +01:00
|
|
|
|
|
|
|
iostats = dict()
|
|
|
|
|
2016-02-25 10:13:46 +01:00
|
|
|
iostats_output = subprocess.check_output([cmd, u'-c', u'iostats'], universal_newlines=True).splitlines()
|
2013-03-04 01:14:34 +01:00
|
|
|
|
2016-02-25 10:13:46 +01:00
|
|
|
for line in iostats_output: iostats[line.split(u':')[0]] = int(line.split(u':')[1])
|
2013-03-04 01:14:34 +01:00
|
|
|
|
2016-02-25 10:13:46 +01:00
|
|
|
print u'received.value ' + unicode(iostats[u'received packets'])
|
|
|
|
print u'sent.value ' + unicode(iostats[u'packets sent'])
|
|
|
|
print u'dropped.value ' + unicode(iostats[u'dropped packets'])
|
|
|
|
print u'ignored.value ' + unicode(iostats[u'ignored packets'])
|
2013-03-04 01:14:34 +01:00
|
|
|
|
|
|
|
sys.exit(0)
|