root / plugins / bsd / uptime_bsd @ bb4d6c64
Historique | Voir | Annoter | Télécharger (1,25 ko)
| 1 | 6272ca0c | iangregory | #!/usr/bin/env perl |
|---|---|---|---|
| 2 | e803e46a | Sec | # -*- perl -*- |
| 3 | 6272ca0c | iangregory | # Plugin to monitor the system uptime |
| 4 | e803e46a | Sec | # |
| 5 | #%# family=auto |
||
| 6 | #%# capabilities=autoconf |
||
| 7 | |||
| 8 | use strict; |
||
| 9 | 6272ca0c | iangregory | use warnings; |
| 10 | e803e46a | Sec | |
| 11 | my %IN; |
||
| 12 | |||
| 13 | my $sysctl = defined($ENV{sysctl}) ? $ENV{sysctl} : '/sbin/sysctl';
|
||
| 14 | 6272ca0c | iangregory | my $ostype = `uname -s`; |
| 15 | chomp ($ostype); |
||
| 16 | e803e46a | Sec | |
| 17 | if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf')) {
|
||
| 18 | 9082a901 | Kenyon Ralph | if ( -x $sysctl ) {
|
| 19 | print "yes\n"; |
||
| 20 | } else {
|
||
| 21 | print "no (sysctl binary not found)\n"; |
||
| 22 | }; |
||
| 23 | exit; |
||
| 24 | e803e46a | Sec | }; |
| 25 | |||
| 26 | if (defined($ARGV[0]) and ($ARGV[0] eq 'config')) {
|
||
| 27 | print <<EOT ; |
||
| 28 | graph_title Uptime |
||
| 29 | graph_args --base 1000 -l 0 |
||
| 30 | graph_vlabel days |
||
| 31 | graph_category system |
||
| 32 | 6272ca0c | iangregory | compile.label Kernel age |
| 33 | e803e46a | Sec | compile.type GAUGE |
| 34 | compile.min 0 |
||
| 35 | compile.max 1000 |
||
| 36 | compile.draw AREA |
||
| 37 | 6272ca0c | iangregory | uptime.label Uptime |
| 38 | e803e46a | Sec | uptime.type GAUGE |
| 39 | uptime.min 0 |
||
| 40 | uptime.max 1000 |
||
| 41 | uptime.draw AREA |
||
| 42 | EOT |
||
| 43 | exit; |
||
| 44 | } |
||
| 45 | |||
| 46 | use Date::Parse; |
||
| 47 | |||
| 48 | my $kern=`sysctl -n kern.version`; |
||
| 49 | $kern=~ /:\s+(.*\S)\s+\w+\@/; |
||
| 50 | fc3bfaeb | Kenyon Ralph | #print "Compile: $1\n"; |
| 51 | bb4d6c64 | Tomohiro Hosaka | $kern= $1 ? str2time($1) : undef; |
| 52 | e803e46a | Sec | |
| 53 | 6272ca0c | iangregory | my $boot=`sysctl -n kern.boottime`; # OpenBSD will return seconds from the epoch |
| 54 | if ($ostype ne "OpenBSD") {
|
||
| 55 | $boot=~ / sec = (\d+)/; |
||
| 56 | fc3bfaeb | Kenyon Ralph | #print "Boot: $1\n"; |
| 57 | 6272ca0c | iangregory | $boot=$1; |
| 58 | } |
||
| 59 | e803e46a | Sec | |
| 60 | my $now=time; |
||
| 61 | |||
| 62 | bb4d6c64 | Tomohiro Hosaka | print "compile.value ",($now-$kern)/60/60/24,"\n" if $kern; |
| 63 | e803e46a | Sec | print "uptime.value ",($now-$boot)/60/60/24,"\n"; |
