root / plugins / swap / swapspace-info @ 17f78427
Historique | Voir | Annoter | Télécharger (4,16 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# Munin plugin for monitoring swapspace usage |
| 3 |
# |
| 4 |
# FIELDS: |
| 5 |
# Swap Alloc swap allocated (used) |
| 6 |
# Swap Unalloc swap reserved but not allocated |
| 7 |
# Swap Avail swap available for reservation |
| 8 |
# |
| 9 |
# Core logic developed by Brendan Gregg. |
| 10 |
# REFERENCE: http://www.brendangregg.com/k9toolkit.html - the swap diagram. |
| 11 |
# |
| 12 |
# COPYRIGHT: Copyright (c) 2004 Brendan Gregg. |
| 13 |
# |
| 14 |
# This program is free software; you can redistribute it and/or |
| 15 |
# modify it under the terms of the GNU General Public License |
| 16 |
# as published by the Free Software Foundation; either version 2 |
| 17 |
# of the License, or (at your option) any later version. |
| 18 |
# |
| 19 |
# This program is distributed in the hope that it will be useful, |
| 20 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
# GNU General Public License for more details. |
| 23 |
# |
| 24 |
# You should have received a copy of the GNU General Public License |
| 25 |
# along with this program; if not, write to the Free Software Foundation, |
| 26 |
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 |
# |
| 28 |
# (http://www.gnu.org/copyleft/gpl.html) |
| 29 |
|
| 30 |
# Perldoc |
| 31 |
|
| 32 |
=pod |
| 33 |
|
| 34 |
=head1 NAME |
| 35 |
|
| 36 |
swapspace_info - Plugin to monitor Swapspace usage |
| 37 |
|
| 38 |
=head1 AUTHOR |
| 39 |
|
| 40 |
Christian Braum, chrisi_braum@web.de |
| 41 |
|
| 42 |
Core logic developed by Brendan Gregg. See K9Toolkit: |
| 43 |
http://www.brendangregg.com/K9Toolkit/swapinfo |
| 44 |
|
| 45 |
=head1 LICENSE |
| 46 |
|
| 47 |
GPL 2. |
| 48 |
|
| 49 |
=cut |
| 50 |
|
| 51 |
# Main |
| 52 |
use strict; |
| 53 |
use warnings; |
| 54 |
|
| 55 |
if ( defined $ARGV[0] ) |
| 56 |
{
|
| 57 |
if ( $ARGV[0] eq "config" ) |
| 58 |
{
|
| 59 |
&config(); |
| 60 |
} |
| 61 |
else |
| 62 |
{
|
| 63 |
&output(); |
| 64 |
} |
| 65 |
} |
| 66 |
else |
| 67 |
{
|
| 68 |
&output(); |
| 69 |
} |
| 70 |
|
| 71 |
sub value |
| 72 |
{
|
| 73 |
my %h_swapvalue; |
| 74 |
eval 'use Sun::Solaris::Kstat; 1;' |
| 75 |
or die 'Please install Sun::Solaris::Kstat'; |
| 76 |
my $Kstat = Sun::Solaris::Kstat->new(); |
| 77 |
|
| 78 |
# --- Fetch Hardware info --- |
| 79 |
### pagesize |
| 80 |
$ENV{PATH} = "/usr/bin";
|
| 81 |
chomp(my $PAGESIZE = `pagesize`); |
| 82 |
my $PAGETOMB = $PAGESIZE / (1024 * 1024); |
| 83 |
my $PAGETOBYTE = $PAGESIZE; |
| 84 |
my $BLOCKTOP = 512 / $PAGESIZE; |
| 85 |
my %VMnow; |
| 86 |
my %VMold; |
| 87 |
my %VMinfo; |
| 88 |
|
| 89 |
# --- Fetch VM info --- |
| 90 |
foreach my $count (0..12) |
| 91 |
{
|
| 92 |
# |
| 93 |
# The values are counters that increment each second, here we |
| 94 |
# check them several times and look for the value changing. |
| 95 |
# (reading them once then again a second later was not reliable). |
| 96 |
# |
| 97 |
foreach my $var ("swap_avail","swap_alloc","swap_free")
|
| 98 |
{
|
| 99 |
$VMnow{$var} = $Kstat->{unix}->{0}->{vminfo}->{$var};
|
| 100 |
unless ($count) |
| 101 |
{
|
| 102 |
$VMold{$var} = $VMnow{$var};
|
| 103 |
next; |
| 104 |
} |
| 105 |
if (($VMnow{$var} != $VMold{$var}) && (! $VMinfo{$var}))
|
| 106 |
{
|
| 107 |
$VMinfo{$var} = $VMnow{$var} - $VMold{$var};
|
| 108 |
} |
| 109 |
} |
| 110 |
select(undef, undef, undef, 0.1); |
| 111 |
$Kstat->update(); |
| 112 |
} |
| 113 |
|
| 114 |
# --- Calculations --- |
| 115 |
|
| 116 |
### Swap |
| 117 |
my $swap_free = $VMinfo{swap_free};
|
| 118 |
my $swap_avail = $VMinfo{swap_avail};
|
| 119 |
my $swap_alloc = $VMinfo{swap_alloc};
|
| 120 |
my $swap_unalloc = $swap_free - $swap_avail; |
| 121 |
|
| 122 |
my $swap_unalloc_B = sprintf( "%d ", $swap_unalloc * $PAGETOBYTE ); |
| 123 |
my $swap_avail_B = sprintf( "%d ", $swap_avail * $PAGETOBYTE ); |
| 124 |
my $swap_alloc_B = sprintf( "%d ", $swap_alloc * $PAGETOBYTE ); |
| 125 |
my $swap_free_B = sprintf( "%d ", $swap_free * $PAGETOBYTE ); |
| 126 |
|
| 127 |
$h_swapvalue{"Alloc.value"} = "$swap_alloc_B";
|
| 128 |
$h_swapvalue{"Unalloc.value"} = "$swap_unalloc_B";
|
| 129 |
$h_swapvalue{"Avail.value"} = "$swap_avail_B";
|
| 130 |
|
| 131 |
return %h_swapvalue; |
| 132 |
} |
| 133 |
|
| 134 |
sub output |
| 135 |
{
|
| 136 |
my %h_swapvalues=value(); |
| 137 |
print "Alloc.value " . $h_swapvalues{"Alloc.value"} . " \n";
|
| 138 |
print "Unalloc.value " . $h_swapvalues{"Unalloc.value"} . " \n";
|
| 139 |
print "Avail.value " . $h_swapvalues{"Avail.value"} . "\n";
|
| 140 |
} |
| 141 |
|
| 142 |
sub config |
| 143 |
{
|
| 144 |
print "graph_args --base 1024 -l 0 \n"; |
| 145 |
print "graph_vlabel Bytes\n"; |
| 146 |
print "graph_title Swapspace usage\n"; |
| 147 |
print "graph_category memory\n"; |
| 148 |
print "graph_info This graph shows what the machine uses Swapspace for.\n"; |
| 149 |
print "graph_order "; |
| 150 |
|
| 151 |
print "Alloc ", |
| 152 |
"Unalloc ", |
| 153 |
"Avail ", |
| 154 |
"\n"; |
| 155 |
|
| 156 |
print "Alloc.label Alloc \n"; |
| 157 |
print "Alloc.draw \n"; |
| 158 |
print "Alloc.info Swap used.\n"; |
| 159 |
print "Unalloc.label Unalloc \n"; |
| 160 |
print "Unalloc.draw \n"; |
| 161 |
print "Unalloc.info Swap reserved but not allocated.\n"; |
| 162 |
print "Avail.label Avail \n"; |
| 163 |
print "Avail.draw \n"; |
| 164 |
print "Avail.info Swap available.\n"; |
| 165 |
} |
