Projet

Général

Profil

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

root / plugins / ntp / ntp_queries @ 17f78427

Historique | Voir | Annoter | Télécharger (3,2 ko)

1
#!/usr/bin/perl -w
2

    
3
# Plugin to monitor ntp queries
4
# (c)2009 Chris Hastie: chris (at) oak (hyphen) wood (dot) co (dot) uk
5
#
6
# Parameters understood:
7
#
8
#   config   (required)
9
#   autoconf (optional - used by munin-node-configure)
10
#
11
# Config variables:
12
#
13
#       ntpdc           - path to ntpdc program
14
#
15
# This program is free software: you can redistribute it and/or modify
16
# it under the terms of the GNU General Public License as published by
17
# the Free Software Foundation, either version 3 of the License, or
18
# (at your option) any later version.
19
#
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
# GNU General Public License for more details.
24
#
25
# You should have received a copy of the GNU General Public License
26
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
#
28
# Change log
29
# v1.0.0    2009-03-11        Chris Hastie
30
# initial release
31
#
32
#
33
#
34
# Magic markers - optional - used by installation scripts and
35
# munin-node-configure:
36
#
37
#%# family=contrib
38
#%# capabilities=autoconf
39
#
40

    
41
use strict;
42
use Socket;
43

    
44
my $NTPDC = $ENV{ntpdc} || "ntpdc";
45
my $COMMAND    =      "$NTPDC -c sysstats";
46

    
47

    
48
# autoconf
49
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
50
    `$NTPDC -c help >/dev/null 2>/dev/null`;
51
    if ($? eq "0") {
52
        if (`$NTPDC -c sysstats | wc -l` > 0) {
53
            print "yes\n";
54
            exit 0;
55
        } else {
56
            print "no (unable to list system stats)\n";
57
            exit 1;
58
        }
59
    } else {
60
        print "no (ntpdc not found)\n";
61
        exit 1;
62
    }
63
}
64

    
65
my $queries = 0;
66
my $packrcv;
67
my $packproc;
68

    
69

    
70
# get data from tc
71
open(SERVICE, "$COMMAND |")
72
  or die("Could not execute '$COMMAND': $!");
73

    
74
while (<SERVICE>) {
75
    if (/^packets received:\s*(\d*)/) {
76
      $packrcv = $1;
77
    }
78
    if (/^packets processed:\s*(\d*)/) {
79
      $packproc = $1;
80
    }
81
    if (/^current version:\s*(\d*)/) {
82
      $queries += $1;
83
    }
84
    if (/^previous version:\s*(\d*)/) {
85
      $queries += $1;
86
    }
87
    if (/^bad version:\s*(\d*)/) {
88
      $queries += $1;
89
    }
90
 #   if (/^access denied:\s*(\d*)/) {
91
 #     $queries += $1;
92
 #   }
93
 #   if (/^bad length or format:\s*(\d*)/) {
94
 #     $queries += $1;
95
 #   }
96
 #   if (/^bad authentication:\s*(\d*)/) {
97
 #     $queries += $1;
98
 #   }
99
 #   if (/^rate exceeded:\s*(\d*)/) {
100
 #     $queries += $1;
101
 #   }
102
}
103
close(SERVICE);
104

    
105
$queries = $queries - $packproc;
106

    
107
# config
108
if ($ARGV[0] and $ARGV[0] eq 'config') {
109
  print "graph_title NTP Queries\n";
110
  print "graph_args --base 1000\n";
111
  print "graph_vlabel qps\n";
112
  print "graph_category time\n";
113
  print "graph_info Queries to the NTP server\n";
114
  print "queries.label Queries per second\n";
115
  print "queries.type DERIVE\n";
116
  print "queries.min 0\n";
117

    
118
  exit 0;
119
}
120

    
121
# send output
122

    
123
print "queries.value $queries\n";
124

    
125
##################################
126

    
127

    
128
=pod
129

    
130
=head1 Description
131

    
132
ntp_queries - A munin plugin to monitor queries handled by NTP
133

    
134
=head1 Parameters understood:
135

    
136
  config   (required)
137
  autoconf (optional - used by munin-node-configure)
138

    
139
=head1 Configuration variables:
140

    
141
All configuration parameters are optional
142

    
143
  ntpdc            - path to ntpdc program
144

    
145

    
146
=head1 Known issues
147

    
148

    
149
=cut