root / plugins / system / dar_memusage @ e5ce7492
Historique | Voir | Annoter | Télécharger (2,64 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# -*- perl -*- |
| 3 |
|
| 4 |
=head1 NAME |
| 5 |
|
| 6 |
dar_mumusage - Munin plugin to monitor darwin physical memory 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 physical memory 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 |
$maxmemcmd = `hostinfo | grep memory`; |
| 63 |
$maxmemcmd =~ m/^.+?: (\d+\.\d+) (\w).+$/; |
| 64 |
$memline = $1; |
| 65 |
if ( $2 eq "m" ) { $memline = $memline * 1024 * 1024; }
|
| 66 |
if ( $2 eq "g" ) { $memline = $memline * 1024 * 1024 * 1024; }
|
| 67 |
|
| 68 |
print "graph_title Memory usage\n"; |
| 69 |
print "graph_args --base 1024 --lower-limit 0 --upper-limit ".$memline." --rigid\n"; |
| 70 |
print "graph_vlabel Bytes\n"; |
| 71 |
print "graph_scale yes\n"; |
| 72 |
print "graph_category system\n"; |
| 73 |
print "wired.label wired\nwired.type GAUGE\nwired.draw AREA\n"; |
| 74 |
print "active.label active\nactive.type GAUGE\nactive.draw STACK\n"; |
| 75 |
print "inactive.label inactive\ninactive.type GAUGE\ninactive.draw STACK\n"; |
| 76 |
print "free.label free\nfree.type GAUGE\nfree.draw STACK\n"; |
| 77 |
print "used.label used\nused.type GAUGE\nused.draw LINE2\n"; |
| 78 |
exit 0; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
@top = `top -l1 -n0 -u`; |
| 83 |
$quit = 0; |
| 84 |
for ( $i = 1; ($i < $#top and $quit == 0); $i++ ) {
|
| 85 |
if ( $top[$i] =~ /^PhysMem/ ) {
|
| 86 |
$wired = $active = $inactive = $free = $used = $top[$i]; |
| 87 |
$wired =~ s/^.+?: (\d+)M wired.+$/$1/; chomp $wired; $wired = $wired * 1024 * 1024; |
| 88 |
$active =~ s/^.+?, (\d+)M active.+$/$1/; chomp $active; $active = $active * 1024 * 1024; |
| 89 |
$inactive =~ s/^.+?, (\d+)M inactive.+$/$1/; chomp $inactive; $inactive = $inactive * 1024 * 1024; |
| 90 |
$free =~ s/^.+?, (\d+)([M|K]) free.+$/$1/; chomp $free; $free = $free * 1024 * 1024; if ( $2 eq "K" ) { $free = $free / 1024; }
|
| 91 |
$used =~ s/^.+?, (\d+)M used.+$/$1/; chomp $used; $used = $used * 1024 * 1024; |
| 92 |
print "wired.value " . $wired . "\n"; |
| 93 |
print "active.value " . $active . "\n"; |
| 94 |
print "inactive.value " . $inactive . "\n"; |
| 95 |
print "free.value " . $free . "\n"; |
| 96 |
print "used.value " . $used . "\n"; |
| 97 |
$quit = 1; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
# vim:syntax=perl |
