1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 18:07:20 +00:00

Plugin-Gallery: get better 2nd level structure

This commit is contained in:
dipohl 2017-02-24 01:35:47 +01:00
parent 45391005a8
commit 3a6fdce80f
13 changed files with 4 additions and 5 deletions

56
plugins/ntp/ntp_kernel_pll_prec Executable file
View file

@ -0,0 +1,56 @@
#!/bin/sh
# -*- sh -*-
: <<EOF
=head1 NAME
ntp_kernel_pll_prec - Plugin to monitor the kernel's PLL precision for
the NTP status
=head1 CONFIGURATION
No configuration
=head1 AUTHORS
Original authors unknown
ntp_kernel_pll_freq patched for PLL precision support by azet@azet.org
=head1 LICENSE
Unknown
=head1 BUGS
None Known
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
EOF
if [ "$1" = "autoconf" ]; then
{ ntpq -c kerninfo; ntpdc -c kerninfo; } 2>/dev/null |
awk 'BEGIN { ev=1; }
/^precision:/ { ev=0; }
END { if (ev == 0) { print "yes";} else { print "no"; } exit ev; }'
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title NTP kernel PLL precision'
echo 'graph_args --alt-autoscale'
echo 'graph_vlabel PLL precision'
echo 'graph_category time'
echo 'graph_info The precision of the kernel phase-locked loop used by NTP'
echo 'ntp_pll_prec.label pll-precision'
echo 'ntp_pll_prec.info Phase-locked loop precision in seconds'
exit 0
fi
CALL=`{ ntpq -c kerninfo; ntpdc -c kerninfo; } 2>/dev/null | awk '/^precision:/ { print $2 }'`
printf "ntp_pll_prec.value %.23f" ${CALL} ; echo

57
plugins/ntp/ntp_kernel_pll_tol Executable file
View file

@ -0,0 +1,57 @@
#!/bin/sh
# -*- sh -*-
: <<EOF
=head1 NAME
ntp_kernel_pll_tol - Plugin to monitor the kernel's PLL frequency tolerance for
the NTP status
=head1 CONFIGURATION
No configuration
=head1 AUTHORS
Original authors unknown
ntp_kernel_pll_freq script patched by azet@azet.org for frequency tolerance support
=head1 LICENSE
Unknown license
=head1 BUGS
None known
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
EOF
if [ "$1" = "autoconf" ]; then
{ ntpq -c kerninfo; ntpdc -c kerninfo; } 2>/dev/null |
awk 'BEGIN { ev=1; }
/^frequency tolerance:/ { ev=0; }
END { if (ev == 0) { print "yes";} else { print "no"; } exit ev; }'
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title NTP kernel PLL frequency tolerance (ppm)'
echo 'graph_args --alt-autoscale'
echo 'graph_vlabel PLL frequency (ppm)'
echo 'graph_category time'
echo 'graph_info The frequency tolerance of the kernel phase-locked loop used by NTP'
echo 'ntp_pll_tol.label pll-tolerance'
echo 'ntp_pll_tol.info Phase-locked loop frequency tolerance in parts per million'
exit 0
fi
echo -n 'ntp_pll_tol.value '
{ ntpq -c kerninfo; ntpdc -c kerninfo; } 2>/dev/null | awk '/^frequency tolerance:/ { print $3 }'

98
plugins/ntp/ntp_packets Executable file
View file

@ -0,0 +1,98 @@
#!/usr/bin/env python3
# -*- 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).
#
# Copyright © 2016 Kenyon Ralph <kenyon@kenyonralph.com>
#
# 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
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print('graph_title NTP traffic')
print('graph_vlabel Packets/${graph_period} received(-)/sent(+)')
print('graph_info This graph shows the packet rates of this ntpd. Bad means packets received with bad length or format. Authfailed means packets for which authentication failed.')
print('graph_category time')
print('received.label Received')
print('received.type DERIVE')
print('received.graph no')
print('received.min 0')
print('sent.label Rx/Tx')
print('sent.type DERIVE')
print('sent.negative received')
print('sent.min 0')
print('dropped.label Dropped')
print('dropped.type DERIVE')
print('dropped.min 0')
print('ignored.label Ignored')
print('ignored.type DERIVE')
print('ignored.min 0')
print('bad.label Bad')
print('bad.type DERIVE')
print('bad.min 0')
print('authfail.label Authfailed')
print('authfail.type DERIVE')
print('authfail.min 0')
print('declined.label Declined')
print('declined.type DERIVE')
print('declined.min 0')
print('restricted.label Restricted')
print('restricted.type DERIVE')
print('restricted.min 0')
print('kod.label KoD responses')
print('kod.type DERIVE')
print('kod.min 0')
sys.exit(0)
os.environ['PATH'] = '/usr/local/sbin:/usr/local/bin:' + os.environ['PATH']
# Assuming that the ntpd version is the same as the ntpq or ntpdc
# version. This is how a proper install should be.
version = subprocess.check_output(['ntpq', '-c', 'version'], universal_newlines=True).split()[1][0:5].replace('.', '')
if int(version) >= 427:
cmd = 'ntpq'
else:
cmd = 'ntpdc'
stats = dict()
stats_output = subprocess.check_output([cmd, '-c', 'iostats', '-c', 'sysstats'], universal_newlines=True).splitlines()
for line in stats_output: stats[line.split(':')[0]] = int(line.split(':')[1])
print('received.value ' + str(stats['received packets']))
print('sent.value ' + str(stats['packets sent']))
print('dropped.value ' + str(stats['dropped packets']))
print('ignored.value ' + str(stats['ignored packets']))
print('bad.value ' + str(stats['bad length or format']))
print('authfail.value ' + str(stats['authentication failed']))
print('declined.value ' + str(stats['declined']))
print('restricted.value ' + str(stats['restricted']))
print('kod.value ' + str(stats['KoD responses']))
sys.exit(0)

231
plugins/ntp/ntp_peers Executable file
View file

@ -0,0 +1,231 @@
#!/usr/bin/perl -w
# -*- perl -*-
# Plugin to monitor offsets to multiple NTP peers.
# NB currently only works for IPv4 peers
#
# (c)2008 Chris Hastie: chris (at) oak (hyphen) wood (dot) co (dot) uk
#
# Updated to version 1.1 by;
# (c)2010 Uffe Norberg: uffe (dot) norberg (at) gmail (dot) com
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-node-configure)
#
# Config variables:
#
# ntpq - path to ntpq program
# statedir - directory in which to place state file
# hostname_<key> - override hostname for peer <key>. <key> is
# an IPv4 address with dots replaced by underscores.
# Useful for reference clocks, eg
# env.hostname_127_127_43_0 .GPS.
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Change log
# v1.0.0 2008-07-21 Chris Hastie
# initial release
#
# v1.1.0 2010-12-07 Uffe Norberg
# - Changed default statedir to /var/lib/munin/plugin-state (Debian default)
# - Changed config output to make rrdtool draw finer lines in graph
# - Changed config output so that rrdtool draws milli- and microseconds correctly
#
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#%# family=contrib
#%# capabilities=autoconf
use strict;
use Socket;
my $NTPQ = $ENV{ntpq} || "ntpq";
my $COMMAND = "$NTPQ -np";
my $statedir = $ENV{statedir} || '/var/lib/munin/plugin-state';
my $statefile = "$statedir/ntp_peers.state";
# autoconf
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
`$NTPQ -c help >/dev/null 2>/dev/null`;
if ($? eq "0") {
if (`$NTPQ -np | 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;
}
}
my %peers;
# retrieve cached list of IPs and hostnames
if (-f "$statefile") {
open (IN, "$statefile") or exit 4;
while (<IN>) {
if (/^([0-9\.]+):(.*)$/) {
$peers{$1}{'name'} = $2;
}
}
close IN;
}
# do custom IP lookups
for my $key (map {/^hostname_(.+)/} keys %ENV) {
my $ip = &desanitize_field($key);
$peers{$ip}{'name'} = $ENV{"hostname_$key"}
}
# get data from ntpq
open(SERVICE, "$COMMAND |")
or die("Could not execute '$COMMAND': $!");
while (<SERVICE>) {
if (/^[-+*#](\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\s+\S+){7}\s+(\S+)/) {
my $name = &lookupname($1);
$peers{$1}{'value'} = $3;
}
}
close(SERVICE);
# config
if ($ARGV[0] and $ARGV[0] eq 'config') {
print "graph_title NTP peer offsets\n";
print "graph_args --base 1000 --vertical-label seconds --lower-limit 0\n";
# print "graph_vlabel ms\n";
print "graph_category time\n";
print "graph_info Offset (in ms) to the server's NTP peers\n";
print "graph_order ";
foreach my $key (sort by_name keys %peers) {
print &sanitize_field($peers{$key}{'name'}) . " ";
}
print "\n";
foreach my $peer (keys %peers) {
print &sanitize_field($peers{$peer}{'name'}) . ".label " . $peers{$peer}{'name'} . "\n";
print &sanitize_field($peers{$peer}{'name'}) . ".draw " . "LINE" . "\n";
print &sanitize_field($peers{$peer}{'name'}) . ".cdef " . &sanitize_field($peers{$peer}{'name'}) . ",1000,/" . "\n";
}
exit 0;
}
# send output
foreach my $peer (keys %peers) {
print &sanitize_field($peers{$peer}{'name'}) . ".value " . &getpeeroffset($peer) . "\n";
}
# save list of peer IPs and hostnames
if(-l $statefile) {
die("$statefile is a symbolic link, refusing to touch it.");
}
open (OUT, ">$statefile") or exit 4;
foreach my $i (keys %peers) {
print OUT "$i:" . $peers{$i}{'name'} . "\n";
}
close OUT;
# sorts by hostname
sub by_name {
return $peers{$a}{'name'} cmp $peers{$b}{'name'};
}
# create a valid munin field name from the hostname
sub sanitize_field () {
my $field = shift;
# replace illegal characters with an underscore
$field =~ s/[^A-Za-z0-9_]/_/g;
# prepend an underscore if name starts with a number
$field =~ s/^([^A-Za-z_])/_$1/;
# truncate to 19 characters
if (length($field) > 19) {
$field = substr($field, 0, 19);
}
return $field
}
# get an IP address from the underscore escaped
# value of env.hostname_<key>
sub desanitize_field () {
my $field = shift;
$field =~ s/_/\./g;
return $field
}
# lookup hostnames
sub lookupname () {
my $ip = shift;
# have we already got it?
if ($peers{$ip}{'name'}) {
return $peers{$ip}{'name'};
}
# else look it up
my $iaddr = inet_aton($ip);
my $name = gethostbyaddr($iaddr, AF_INET) || $ip;
# add to cache
$peers{$ip}{'name'} = $name;
return $name;
}
# returns the offset, or U if it is undefined
sub getpeeroffset() {
my $ip = shift;
my $rtn = 'U';
if (exists($peers{$ip}{'value'})) {
$rtn = $peers{$ip}{'value'};
}
return $rtn
}
=pod
=head1 Description
ntp_peers - A munin plugin to monitor offsets to multiple NTP peers and
graph them on a single graph
=head1 Parameters understood:
config (required)
autoconf (optional - used by munin-node-configure)
=head1 Configuration variables:
All configuration parameters are optional
ntpq - path to ntpq program
statedir - directory in which to place state file
hostname_<key> - override hostname for peer <key>. <key> is
an IPv4 address with dots replaced by underscores.
Useful for reference clocks, eg
env.hostname_127_127_43_0 .GPS.
=head1 Known issues
ntp_peers will not monitor IPv6 peers
=cut

189
plugins/ntp/ntp_peers_ipv6 Executable file
View file

@ -0,0 +1,189 @@
#!/usr/bin/perl -w
# Plugin to monitor offsets to multiple NTP peers.
# NB currently only works for IPv4 peers
#
# (c)2008 Chris Hastie: chris (at) oak (hyphen) wood (dot) co (dot) uk
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-node-configure)
#
# Config variables:
#
# ntpq - path to ntpq program
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Change log
# v1.0.0 2008-07-21 Chris Hastie
# initial release
# v1.0.1 2009-06-05 Tony Hoyle
# ipv6 support. Remove dns lookups.
#
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#
#%# family=contrib
#%# capabilities=autoconf
#
use strict;
my $NTPQ = $ENV{ntpq} || "ntpq";
my $COMMAND = "$NTPQ -nc associations";
my $statedir = $ENV{statedir} || '/usr/local/var/munin/plugin-state';
my $statefile = "$statedir/ntp_peers.state";
# autoconf
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
`$NTPQ -c help >/dev/null 2>/dev/null`;
if ($? eq "0") {
if (`$NTPQ -np | 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;
}
}
my %peers;
# get data from ntpq
open(SERVICE, "$COMMAND |")
or die("Could not execute '$COMMAND': $!");
while (<SERVICE>) {
if(/^\s*\d+\s+(\d+)\s+/) {
my ($name, $offset) = &lookupip($1);
$peers{$name} = $offset;
}
}
close(SERVICE);
# config
if ($ARGV[0] and $ARGV[0] eq 'config') {
print "graph_title NTP peer offsets\n";
print "graph_args --base 1000\n";
print "graph_vlabel ms\n";
print "graph_category time\n";
print "graph_info Offset (in ms) to the server's NTP peers\n";
print "graph_order ";
foreach my $key (sort keys %peers) {
print &sanitize_field($key) . " ";
}
print "\n";
foreach my $peer (keys %peers) {
print &sanitize_field($peer) . ".label " . $peer . "\n";
}
exit 0;
}
# send output
foreach my $peer (keys %peers) {
print &sanitize_field($peer) . ".value " . &getpeeroffset($peer) . "\n";
}
# create a valid munin field name from the hostname
sub sanitize_field () {
my $field = shift;
# replace illegal characters with an underscore
$field =~ s/[^A-Za-z0-9_]/_/g;
# prepend an underscore if name starts with a number
$field =~ s/^([^A-Za-z_])/_$1/;
# truncate to 19 characters
if (length($field) > 19) {
$field = substr($field, 0, 19);
}
return $field
}
# get an IP address from the underscore escaped
# value of env.hostname_<key>
sub desanitize_field () {
my $field = shift;
$field =~ s/_/\./g;
return $field
}
# Get name, offset info for peers
# It would be more efficient to use mrv here to avoid rerunning ntpq
sub lookupip() {
my $assocID = shift;
my $CMD = "$NTPQ -c \"rv $assocID srcadr,offset\"";
my $addr="";
my $offset="";
# get data from ntpq
open(SERVICE2, "$CMD |")
or die("Could not execute '$CMD': $!");
while(<SERVICE2>) {
if(/^srcadr=([^\s]+),\soffset=(.+)$/) {
$addr = $1;
$offset = $2;
}
}
close(SERVICE2);
return ($addr, $offset);
}
# returns the offset, or U if it is undefined
sub getpeeroffset() {
my $name = shift;
my $rtn = 'U';
if (exists($peers{$name})) {
$rtn = $peers{$name};
}
return $rtn
}
=pod
=head1 Description
ntp_peers - A munin plugin to monitor offsets to multiple NTP peers and
graph them on a single graph
=head1 Parameters understood:
config (required)
autoconf (optional - used by munin-node-configure)
=head1 Configuration variables:
All configuration parameters are optional
ntpq - path to ntpq program
statedir - directory in which to place state file
hostname_<key> - override hostname for peer <key>. <key> is
an IPv4 address with dots replaced by underscores.
Useful for reference clocks, eg
env.hostname_127_127_43_0 .GPS.
=head1 Known issues
ntp_peers will not monitor IPv6 peers
=cut

85
plugins/ntp/ntp_pool_score_ Executable file
View file

@ -0,0 +1,85 @@
#!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
ntp_pool_score_ - Wildcard plugin to monitor the score assigned to a server
from pool.ntp.org . This is achieved by fetching the cvs data from
http://www.pool.ntp.org/scores/IP_ADDRESS/log?limit=1 using wget.
=head1 CONFIGURATION
This is a wildcard plugin. The wildcard suffix link will be the server to be
monitored.
This plugin uses the following configuration variables:
[ntp_pool_score_*]
env.warning - score below which a warning will be triggered
env.critical - score below which the value becomes critical
=head2 DEFAULT CONFIGURATION
The default configuration is to set warning to 15 and critical to 10.
=head2 EXAMPLE WILDCARD USAGE
C<ln -s /usr/share/munin/plugins/ntp_pool_score_ /etc/munin/plugins/ntp_pool_score_SERVER_IP
...will monitor the score of the server with ip address SERVER_IP
=head1 AUTHOR
Tocho Tochev
tocho AT tochev DOT net
=head1 LICENSE
GNU General Public License, version 2
http://www.gnu.org/licenses/gpl-2.0.html
=head1 MAGIC MARKERS
#%# family=manual
=cut
target=`basename $0 | sed 's/^ntp_pool_score_//g'`
if [ "$target"x = "x" ]; then
echo "Please call using ntp_pool_score_IP" >&2
exit 1
fi
# Check if config was requested
if [ "$1" = "config" ]; then
# Configure graph
echo "graph_title NTP Pool Score for $target"
echo 'graph_args -l -25 -u 25'
echo 'graph_vlabel Score'
echo 'graph_category time'
echo "graph_info NTP Pool Score for $target"
echo "score.warning ${warning:-15}":
echo "score.critical ${critical:-10}":
echo "score.info Score for $target"
echo "score.label score"
exit 0
fi
# Get the score
# the score can be a bit outdated but do not worry about that
SCORE=$(wget "http://www.pool.ntp.org/scores/$target/log?limit=1" \
--timeout=30 -O - 2>/dev/null \
| tail -n 1 | awk -F ',' '{print $5}')
if echo "$SCORE" | grep -q '^-\?[0-9.]\+$'; then
echo "score.value $SCORE"
else
echo "score.value U"
fi

150
plugins/ntp/ntp_queries Executable file
View file

@ -0,0 +1,150 @@
#!/usr/bin/perl -w
# Plugin to monitor ntp queries
# (c)2009 Chris Hastie: chris (at) oak (hyphen) wood (dot) co (dot) uk
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-node-configure)
#
# Config variables:
#
# ntpdc - path to ntpdc program
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Change log
# v1.0.0 2009-03-11 Chris Hastie
# initial release
#
#
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#
#%# family=contrib
#%# capabilities=autoconf
#
use strict;
use Socket;
my $NTPDC = $ENV{ntpdc} || "ntpdc";
my $COMMAND = "$NTPDC -c sysstats";
# autoconf
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
`$NTPDC -c help >/dev/null 2>/dev/null`;
if ($? eq "0") {
if (`$NTPDC -c sysstats | wc -l` > 0) {
print "yes\n";
exit 0;
} else {
print "no (unable to list system stats)\n";
exit 1;
}
} else {
print "no (ntpdc not found)\n";
exit 1;
}
}
my $queries = 0;
my $packrcv;
my $packproc;
# get data from tc
open(SERVICE, "$COMMAND |")
or die("Could not execute '$COMMAND': $!");
while (<SERVICE>) {
if (/^packets received:\s*(\d*)/) {
$packrcv = $1;
}
if (/^packets processed:\s*(\d*)/) {
$packproc = $1;
}
if (/^current version:\s*(\d*)/) {
$queries += $1;
}
if (/^previous version:\s*(\d*)/) {
$queries += $1;
}
if (/^bad version:\s*(\d*)/) {
$queries += $1;
}
# if (/^access denied:\s*(\d*)/) {
# $queries += $1;
# }
# if (/^bad length or format:\s*(\d*)/) {
# $queries += $1;
# }
# if (/^bad authentication:\s*(\d*)/) {
# $queries += $1;
# }
# if (/^rate exceeded:\s*(\d*)/) {
# $queries += $1;
# }
}
close(SERVICE);
$queries = $queries - $packproc;
# config
if ($ARGV[0] and $ARGV[0] eq 'config') {
print "graph_title NTP Queries\n";
print "graph_args --base 1000\n";
print "graph_vlabel qps\n";
print "graph_category time\n";
print "graph_info Queries to the NTP server\n";
print "queries.label Queries per second\n";
print "queries.type DERIVE\n";
print "queries.min 0\n";
exit 0;
}
# send output
print "queries.value $queries\n";
##################################
=pod
=head1 Description
ntp_queries - A munin plugin to monitor queries handled by NTP
=head1 Parameters understood:
config (required)
autoconf (optional - used by munin-node-configure)
=head1 Configuration variables:
All configuration parameters are optional
ntpdc - path to ntpdc program
=head1 Known issues
=cut

50
plugins/ntp/ntpdate_ Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
#
# Plugin to monitor clock offset and delay, using ntpdate
#
# Parameters understood:
#
# config (required)
#
# Author: Rune Nordbøe Skillingstad <rune.skillingstad@ntnu.no>
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#
#%# family=manual
#%# capabilities=
#
NTPDATE="/usr/sbin/ntpdate"
PEER=$(basename $0 | sed -e 's/^ntpdate_//' -e 's/_/./g')
if [ ! -x "$NTPDATE" ]; then
echo "Can't find ntpdate executable"
exit 1
fi
if [ "$PEER" = "" ]; then
echo "Unknown peer"
exit 1
fi
if [ "$1" = "config" ]; then
echo "graph_title NTP offset and delay to peer $PEER"
echo "graph_category time"
echo "graph_args --base 1000 --vertical-label msec"
echo "offset.label Offset"
echo "offset.draw LINE2"
echo "delay.label Delay"
echo "delay.draw LINE2"
exit 0
fi
LANG=en_US
DATA=($($NTPDATE -q $PEER | awk '/^server.*offset/{gsub(/,/,"");if(dela==0||$8<dela){offs=$6;dela=$8;}}END{print offs*1000,dela*1000;}'))
[ -z "$DATA" -o "x$DATA" = "x0" ] && exit 1
echo "offset.value ${DATA[0]}"
echo "delay.value ${DATA[1]}"
exit 0