File: ntp_.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (122 lines) | stat: -rwxr-xr-x 2,821 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!@@PERL@@ -w
#
# Plugin to monitor NTP statistics
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-node-configure)
#       suggest  (optional - used by munin-node-configure)
#
# $Log$
# Revision 1.4  2004/11/21 20:19:09  jimmyo
# Don't suggest localhost peer.
#
# Revision 1.3  2004/11/21 20:12:32  jimmyo
# Cosmetics.
#
# Revision 1.2  2004/11/21 19:55:28  jimmyo
# Upped generic/ntp_ to auto family.
#
# Revision 1.1  2004/11/21 19:35:23  jimmyo
# Corrected file name.
#
# Revision 1.2  2004/09/08 15:25:33  ilmari
# Use @@PERL@@ in all perl shebang lines.
#
# Revision 1.1  2004/01/30 15:07:38  jimmyo
# Added generic plugins ntp_ and ntp_states to manual family (SF#887000).
#
#
#
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#
#%# family=auto
#%# capabilities=autoconf suggest
#

use strict;
use Net::hostent;
use Socket;

if ($ARGV[0] and $ARGV[0] eq "autoconf") {
	`ntpq -c help >/dev/null 2>/dev/null`;
	if ($? eq "0") {
		if (`ntpq -c "hostnames no" -c peers | wc -l` > 0) {
			print "yes\n";
			exit 0;
		} else {
			print "no (unable to list peers)\n";
			exit 1;
		}
	} else {
		print "no (ntpq not found)\n";
		exit 1;
	}
}

if ($ARGV[0] and $ARGV[0] eq "suggest") {
	my @lines = `ntpq -c "hostnames no" -c peers`;
	foreach (@lines) {
		next unless /^.(\d+\.\d+\.\d+\.\d+)/;
		next if /^.224\.0\.1\.1/;
		next if /^.127\./;
		my $addr = $1;
		my $name = gethostbyaddr(inet_aton($addr));
		$name = defined $name ? $name->name : $addr;
		$name =~ s/[\.-]/_/g;
		print $name, "\n";
	}
	exit 0;
}

$0 =~ /ntp_(.+)*$/; 
my $name = $1;
exit 2 unless defined $name;

if ($ARGV[0] and $ARGV[0] eq "config") {
	my @lines = `ntpq -c "hostnames no" -c peers`;
	my $host;
	foreach (@lines) {
		next unless /^.(\d+\.\d+\.\d+\.\d+)/;
		next if /^.224\.0\.1\.1/;
		my $addr = $1;
		my $host = gethostbyaddr(inet_aton($addr));
		$host = defined $host ? $host->name : $addr;
		my $host_ = $host;
		$host_ =~ s/[\.-]/_/g;
		next unless $host_ eq $name;
		print "graph_title NTP statistics for peer $host\n";
	}
	print "graph_args --base 1000 --vertical-label msec --lower-limit 0\n";
        print "delay.label Delay\n";
        print "delay.draw LINE2\n";
        print "offset.label Offset\n";
        print "offset.draw LINE2\n";
        print "jitter.label Jitter\n";
        print "jitter.draw LINE2\n";
        exit 0;
}

my @lines = `ntpq -c "hostnames no" -c peers`;
foreach (@lines) {
	next unless /^.(\d+\.\d+\.\d+\.\d+)/;
	next if /^.224\.0\.1\.1/;
	my $addr = $1;
	my $host = gethostbyaddr(inet_aton($addr));
	$host = defined $host ? $host->name : $addr;
	$host =~ s/[\.-]/_/g;
	next unless $host eq $name;
	my @F = split;
	print <<"EOT";
delay.value $F[7]
offset.value $F[8]
jitter.value $F[9]
EOT
}

exit 0;

# vim:syntax=perl