root / plugins / ntp / ntp_packets @ 585f6f15
Historique | Voir | Annoter | Télécharger (3,66 ko)
| 1 | c00f7af9 | Kenyon Ralph | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | 5f0fd4e5 | Kenyon Ralph | # -*- 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 | c51f9d32 | Kenyon Ralph | # Copyright © 2016 Kenyon Ralph <kenyon@kenyonralph.com> |
| 17 | 5f0fd4e5 | Kenyon Ralph | # |
| 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 | c00f7af9 | Kenyon Ralph | 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 | 585f6f15 | Lars Kruse | print('graph_info This graph shows the packet rates of this ntpd. Bad means packets received '
|
| 38 | 'with bad length or format. Authfailed means packets for which authentication failed.') |
||
| 39 | c00f7af9 | Kenyon Ralph | print('graph_category time')
|
| 40 | print('received.label Received')
|
||
| 41 | print('received.type DERIVE')
|
||
| 42 | print('received.graph no')
|
||
| 43 | print('received.min 0')
|
||
| 44 | print('sent.label Rx/Tx')
|
||
| 45 | print('sent.type DERIVE')
|
||
| 46 | print('sent.negative received')
|
||
| 47 | print('sent.min 0')
|
||
| 48 | print('dropped.label Dropped')
|
||
| 49 | print('dropped.type DERIVE')
|
||
| 50 | print('dropped.min 0')
|
||
| 51 | print('ignored.label Ignored')
|
||
| 52 | print('ignored.type DERIVE')
|
||
| 53 | print('ignored.min 0')
|
||
| 54 | c51f9d32 | Kenyon Ralph | print('bad.label Bad')
|
| 55 | print('bad.type DERIVE')
|
||
| 56 | print('bad.min 0')
|
||
| 57 | print('authfail.label Authfailed')
|
||
| 58 | print('authfail.type DERIVE')
|
||
| 59 | print('authfail.min 0')
|
||
| 60 | print('declined.label Declined')
|
||
| 61 | print('declined.type DERIVE')
|
||
| 62 | print('declined.min 0')
|
||
| 63 | print('restricted.label Restricted')
|
||
| 64 | print('restricted.type DERIVE')
|
||
| 65 | print('restricted.min 0')
|
||
| 66 | print('kod.label KoD responses')
|
||
| 67 | print('kod.type DERIVE')
|
||
| 68 | print('kod.min 0')
|
||
| 69 | 5f0fd4e5 | Kenyon Ralph | sys.exit(0) |
| 70 | |||
| 71 | c00f7af9 | Kenyon Ralph | os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:' + os.environ['PATH'] |
| 72 | 5f0fd4e5 | Kenyon Ralph | |
| 73 | # Assuming that the ntpd version is the same as the ntpq or ntpdc |
||
| 74 | # version. This is how a proper install should be. |
||
| 75 | |||
| 76 | 585f6f15 | Lars Kruse | version = subprocess.check_output(['ntpq', '-c', 'version'], |
| 77 | universal_newlines=True).split()[1][0:5].replace('.', '')
|
||
| 78 | 5f0fd4e5 | Kenyon Ralph | |
| 79 | if int(version) >= 427: |
||
| 80 | c00f7af9 | Kenyon Ralph | cmd = 'ntpq' |
| 81 | 5f0fd4e5 | Kenyon Ralph | else: |
| 82 | c00f7af9 | Kenyon Ralph | cmd = 'ntpdc' |
| 83 | 5f0fd4e5 | Kenyon Ralph | |
| 84 | c51f9d32 | Kenyon Ralph | stats = dict() |
| 85 | 5f0fd4e5 | Kenyon Ralph | |
| 86 | 585f6f15 | Lars Kruse | stats_output = subprocess.check_output([cmd, '-c', 'iostats', '-c', 'sysstats'], |
| 87 | universal_newlines=True).splitlines() |
||
| 88 | 5f0fd4e5 | Kenyon Ralph | |
| 89 | 585f6f15 | Lars Kruse | for line in stats_output: |
| 90 | stats[line.split(':')[0]] = int(line.split(':')[1])
|
||
| 91 | 5f0fd4e5 | Kenyon Ralph | |
| 92 | c51f9d32 | Kenyon Ralph | print('received.value ' + str(stats['received packets']))
|
| 93 | print('sent.value ' + str(stats['packets sent']))
|
||
| 94 | print('dropped.value ' + str(stats['dropped packets']))
|
||
| 95 | print('ignored.value ' + str(stats['ignored packets']))
|
||
| 96 | print('bad.value ' + str(stats['bad length or format']))
|
||
| 97 | print('authfail.value ' + str(stats['authentication failed']))
|
||
| 98 | print('declined.value ' + str(stats['declined']))
|
||
| 99 | print('restricted.value ' + str(stats['restricted']))
|
||
| 100 | print('kod.value ' + str(stats['KoD responses']))
|
||
| 101 | 5f0fd4e5 | Kenyon Ralph | |
| 102 | sys.exit(0) |
