root / plugins / time / ntp_packets @ c00f7af9
Historique | Voir | Annoter | Télécharger (2,79 ko)
| 1 |
#!/usr/bin/env python3 |
|---|---|
| 2 |
# -*- python -*- |
| 3 |
|
| 4 |
# This plugin graphs the rate of sent, received, ignored, and dropped |
| 5 |
# NTP packets for an ntpd process. Similarly to the if_ plugins, |
| 6 |
# received packets are graphed as negative values, and sent packets |
| 7 |
# are graphed as positive values. Ignored and dropped packets are |
| 8 |
# graphed as positive values. |
| 9 |
# |
| 10 |
# The values are retrieved using ntpq or ntpdc, depending on the |
| 11 |
# version of the NTP distribution. |
| 12 |
# |
| 13 |
# Symlink this plugin into the node's plugins directory (like |
| 14 |
# /etc/munin/plugins). |
| 15 |
# |
| 16 |
# Copyright © 2013 Kenyon Ralph <kenyon@kenyonralph.com> |
| 17 |
# |
| 18 |
# This program is free software. It comes without any warranty, to the |
| 19 |
# extent permitted by applicable law. You can redistribute it and/or |
| 20 |
# modify it under the terms of the Do What The Fuck You Want To Public |
| 21 |
# License, Version 2, as published by Sam Hocevar. See |
| 22 |
# http://www.wtfpl.net/ for more details. |
| 23 |
# |
| 24 |
# The latest version of this plugin can be found in the munin contrib |
| 25 |
# repository at https://github.com/munin-monitoring/contrib. Issues |
| 26 |
# with this plugin may be reported there. Patches accepted through the |
| 27 |
# normal github process of forking the repository and submitting a |
| 28 |
# pull request with your commits. |
| 29 |
|
| 30 |
import os |
| 31 |
import subprocess |
| 32 |
import sys |
| 33 |
|
| 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 |
sys.exit(0) |
| 54 |
|
| 55 |
os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:' + os.environ['PATH'] |
| 56 |
|
| 57 |
# Assuming that the ntpd version is the same as the ntpq or ntpdc |
| 58 |
# version. This is how a proper install should be. |
| 59 |
|
| 60 |
version = subprocess.check_output(['ntpq', '-c', 'version'], universal_newlines=True).split()[1][0:5].replace('.', '')
|
| 61 |
|
| 62 |
if int(version) >= 427: |
| 63 |
cmd = 'ntpq' |
| 64 |
else: |
| 65 |
cmd = 'ntpdc' |
| 66 |
|
| 67 |
iostats = dict() |
| 68 |
|
| 69 |
iostats_output = subprocess.check_output([cmd, '-c', 'iostats'], universal_newlines=True).splitlines() |
| 70 |
|
| 71 |
for line in iostats_output: iostats[line.split(':')[0]] = int(line.split(':')[1])
|
| 72 |
|
| 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 |
|
| 78 |
sys.exit(0) |
