root / plugins / time / ntp_queries @ 430d68ff
Historique | Voir | Annoter | Télécharger (3,23 ko)
| 1 | 686406c5 | Chris Hastie | #!/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 | } |
||
| 104 | close(SERVICE); |
||
| 105 | |||
| 106 | $queries = $queries - $packproc; |
||
| 107 | |||
| 108 | # config |
||
| 109 | if ($ARGV[0] and $ARGV[0] eq 'config') {
|
||
| 110 | print "graph_title NTP Queries\n"; |
||
| 111 | print "graph_args --base 1000\n"; |
||
| 112 | print "graph_vlabel qps\n"; |
||
| 113 | print "graph_category ntp\n"; |
||
| 114 | print "graph_info Queries to the NTP server\n"; |
||
| 115 | print "queries.label Queries per second\n"; |
||
| 116 | print "queries.type DERIVE\n"; |
||
| 117 | print "queries.min 0\n"; |
||
| 118 | |||
| 119 | exit 0; |
||
| 120 | } |
||
| 121 | |||
| 122 | # send output |
||
| 123 | |||
| 124 | print "queries.value $queries\n"; |
||
| 125 | |||
| 126 | ################################## |
||
| 127 | |||
| 128 | |||
| 129 | =pod |
||
| 130 | |||
| 131 | =head1 Description |
||
| 132 | |||
| 133 | ntp_queries - A munin plugin to monitor queries handled by NTP |
||
| 134 | |||
| 135 | =head1 Parameters understood: |
||
| 136 | |||
| 137 | config (required) |
||
| 138 | autoconf (optional - used by munin-node-configure) |
||
| 139 | |||
| 140 | =head1 Configuration variables: |
||
| 141 | |||
| 142 | All configuration parameters are optional |
||
| 143 | |||
| 144 | ntpdc - path to ntpdc program |
||
| 145 | |||
| 146 | |||
| 147 | =head1 Known issues |
||
| 148 | |||
| 149 | |||
| 150 | =cut |
