root / plugins / darwin / dar_cpuusage @ 17f78427
Historique | Voir | Annoter | Télécharger (1,91 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# -*- perl -*- |
| 3 |
|
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
dar_cpuusage - Munin plugin to monitor darwin cpu usage. |
| 7 |
|
| 8 |
=head1 APPLICABLE SYSTEMS |
| 9 |
|
| 10 |
Should work on any darwin (Mac OS X) system with the 'top' command. |
| 11 |
|
| 12 |
=head1 CONFIGURATION |
| 13 |
|
| 14 |
None needed |
| 15 |
|
| 16 |
=head1 INTERPRETATION |
| 17 |
|
| 18 |
The plugin runs the top command and shows the CPU usage for the machine. |
| 19 |
|
| 20 |
=head1 BUGS |
| 21 |
|
| 22 |
The stats are a snapshot at the time of the command - a 5 minute average would |
| 23 |
be better. |
| 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/top" ) { print "no (top 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 CPU usage\n"; |
| 63 |
print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100\n"; |
| 64 |
print "graph_vlabel %\n"; |
| 65 |
print "graph_scale no\n"; |
| 66 |
print "graph_category system\n"; |
| 67 |
print "sys.label system\n"; |
| 68 |
print "sys.type GAUGE\n"; |
| 69 |
print "sys.min 0\nsys.draw AREA\n"; |
| 70 |
print "user.label user\n"; |
| 71 |
print "user.type GAUGE\n"; |
| 72 |
print "user.min 0\nuser.draw STACK\n"; |
| 73 |
print "idle.label idle\n"; |
| 74 |
print "idle.type GAUGE\n"; |
| 75 |
print "idle.min 0\nidle.draw STACK\n"; |
| 76 |
exit 0; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
@top = `top -l1 -n0 -u`; |
| 81 |
$quit = 0; |
| 82 |
for ( $i = 1; ($i < $#top and $quit == 0); $i++ ) {
|
| 83 |
if ( $top[$i] =~ /^CPU/ ) {
|
| 84 |
$usr = $sys = $idl = $top[$i]; |
| 85 |
$usr =~ s/^.+?: (\d+\.\d+)\% user.+$/$1/; |
| 86 |
chomp($usr); |
| 87 |
$sys =~ s/^.+?, (\d+\.\d+)\% sys.+$/$1/; |
| 88 |
chomp($sys); |
| 89 |
$idl =~ s/^.+?, (\d+\.\d+)\% idle.+$/$1/; |
| 90 |
chomp($idl); |
| 91 |
print "sys.value " . $sys . "\n"; |
| 92 |
print "user.value " . $usr . "\n"; |
| 93 |
print "idle.value " . $idl . "\n"; |
| 94 |
$quit = 1; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
# vim:syntax=perl |
