Projet

Général

Profil

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

root / plugins / darwin / dar_uptime @ 6ffdebec

Historique | Voir | Annoter | Télécharger (1,84 ko)

1
#!/usr/bin/perl 
2
# -*- perl -*-
3

    
4
=head1 NAME
5

    
6
dar_uptime - Munin plugin to monitor darwin system uptime.
7

    
8
=head1 APPLICABLE SYSTEMS
9

    
10
Should work on any darwin (Mac OS X) system with the 'uptime' command.
11

    
12
=head1 CONFIGURATION
13

    
14
None needed
15

    
16
=head1 INTERPRETATION
17

    
18
The plugin runs the uptime command, and parses the value into days.
19

    
20
=head1 BUGS
21

    
22
Limited test data set, probably fails some of the time - very likely
23
on systems with a very low uptime.
24

    
25
=head1 MAGIC MARKERS
26

    
27
  #%# family=auto
28
  #%# capabilities=autoconf
29

    
30
=head1 VERSION
31

    
32
  v.0.0.1
33

    
34
=head1 AUTHOR
35

    
36
Copyright (C) 2010.
37

    
38
Original version by J.T.Sage (at) gmail (dot) com.
39

    
40
=head1 LICENSE
41

    
42
GPLv2
43

    
44
=cut
45

    
46
use Munin::Plugin;
47

    
48
if ( defined($ARGV[0])) {
49
    if ($ARGV[0] eq 'autoconf') {
50
	$uname = `uname`;
51
	if ( not ( $uname =~ /Darwin/ ) ) { print "no (not a Darwin System)\n"; }
52
	else {
53
		if ( not -x "/usr/bin/uptime" ) { print "no (uptime not found)\n"; }
54
		else {
55
			print "yes\n";
56
		}
57
	}
58
	exit 0;
59
    }
60

    
61
    if ( $ARGV[0] eq "config" ) {
62
	print "graph_title Uptime\n";
63
	print "graph_args --base 1000 -l 0 \n";
64
	print "graph_vlabel uptime in days\n";
65
	print "graph_category system\n";
66
	print "uptime.label uptime\n";
67
	print "uptime.draw AREA\n";
68
	exit 0;
69
    }
70
}
71

    
72
@uptime = `/usr/bin/uptime`; 
73
foreach(@uptime) {
74
	$_ =~ m/^.+up (.+?), \d+ us.+$/;
75
	$timestr = $1; 
76
	if ( $timestr =~ m/^(\d+) day.+?$/ ) {
77
		$days = $1;
78
	} else { $days = 0; }
79
	if ( $timestr =~ m/(\d+) h/ ) {
80
		$hrs = $1;
81
	} else { $hrs = 0; }
82
	if ( $timestr =~ m/(\d+)\:(\d+)/ ) {
83
		$hours = $1; $min = $2;
84
	} else { $hours = 0; $min = 0; }
85
	if ( $timestr =~ m/(\d+) m/ ) {
86
		$mint = $1;
87
	} else {
88
		$mint = 0;
89
	}
90
	$total = ( $days * 24 * 60 * 60 ) + ( ( $hrs + $hours ) * 60 * 60 ) + ( ( $min + $mint ) * 60 );
91
	$daysf = $total / ( 24 * 60 * 60 );
92
	$daysi = ( int( $daysf * 1000 ) / 1000 );
93
	print "uptime.value " . $daysi . "\n";
94
}
95

    
96
# vim:syntax=perl