Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / time / ntp_packets @ c00f7af9

Historique | Voir | Annoter | Télécharger (2,79 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 c00f7af9 Kenyon Ralph
# Copyright © 2013 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
    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 5f0fd4e5 Kenyon Ralph
    sys.exit(0)
54
55 c00f7af9 Kenyon Ralph
os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:' + os.environ['PATH']
56 5f0fd4e5 Kenyon Ralph
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 c00f7af9 Kenyon Ralph
version = subprocess.check_output(['ntpq', '-c', 'version'], universal_newlines=True).split()[1][0:5].replace('.', '')
61 5f0fd4e5 Kenyon Ralph
62
if int(version) >= 427:
63 c00f7af9 Kenyon Ralph
    cmd = 'ntpq'
64 5f0fd4e5 Kenyon Ralph
else:
65 c00f7af9 Kenyon Ralph
    cmd = 'ntpdc'
66 5f0fd4e5 Kenyon Ralph
67
iostats = dict()
68
69 c00f7af9 Kenyon Ralph
iostats_output = subprocess.check_output([cmd, '-c', 'iostats'], universal_newlines=True).splitlines()
70 5f0fd4e5 Kenyon Ralph
71 c00f7af9 Kenyon Ralph
for line in iostats_output: iostats[line.split(':')[0]] = int(line.split(':')[1])
72 5f0fd4e5 Kenyon Ralph
73 c00f7af9 Kenyon Ralph
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 5f0fd4e5 Kenyon Ralph
78
sys.exit(0)