root / plugins / system / swapspace-info @ e5ce7492
Historique | Voir | Annoter | Télécharger (4,1 ko)
| 1 | abaf4133 | Christian B | #!/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 | use Sun::Solaris::Kstat; |
||
| 75 | my $Kstat = Sun::Solaris::Kstat->new(); |
||
| 76 | |||
| 77 | # --- Fetch Hardware info --- |
||
| 78 | ### pagesize |
||
| 79 | $ENV{PATH} = "/usr/bin";
|
||
| 80 | chomp(my $PAGESIZE = `pagesize`); |
||
| 81 | my $PAGETOMB = $PAGESIZE / (1024 * 1024); |
||
| 82 | my $PAGETOBYTE = $PAGESIZE; |
||
| 83 | my $BLOCKTOP = 512 / $PAGESIZE; |
||
| 84 | my %VMnow; |
||
| 85 | my %VMold; |
||
| 86 | my %VMinfo; |
||
| 87 | |||
| 88 | # --- Fetch VM info --- |
||
| 89 | foreach my $count (0..12) |
||
| 90 | {
|
||
| 91 | # |
||
| 92 | # The values are counters that increment each second, here we |
||
| 93 | # check them several times and look for the value changing. |
||
| 94 | # (reading them once then again a second later was not reliable). |
||
| 95 | # |
||
| 96 | foreach my $var ("swap_avail","swap_alloc","swap_free")
|
||
| 97 | {
|
||
| 98 | $VMnow{$var} = $Kstat->{unix}->{0}->{vminfo}->{$var};
|
||
| 99 | unless ($count) |
||
| 100 | {
|
||
| 101 | $VMold{$var} = $VMnow{$var};
|
||
| 102 | next; |
||
| 103 | } |
||
| 104 | if (($VMnow{$var} != $VMold{$var}) && (! $VMinfo{$var}))
|
||
| 105 | {
|
||
| 106 | $VMinfo{$var} = $VMnow{$var} - $VMold{$var};
|
||
| 107 | } |
||
| 108 | } |
||
| 109 | select(undef, undef, undef, 0.1); |
||
| 110 | $Kstat->update(); |
||
| 111 | } |
||
| 112 | |||
| 113 | # --- Calculations --- |
||
| 114 | |||
| 115 | ### Swap |
||
| 116 | my $swap_free = $VMinfo{swap_free};
|
||
| 117 | my $swap_avail = $VMinfo{swap_avail};
|
||
| 118 | my $swap_alloc = $VMinfo{swap_alloc};
|
||
| 119 | my $swap_unalloc = $swap_free - $swap_avail; |
||
| 120 | |||
| 121 | my $swap_unalloc_B = sprintf( "%d ", $swap_unalloc * $PAGETOBYTE ); |
||
| 122 | my $swap_avail_B = sprintf( "%d ", $swap_avail * $PAGETOBYTE ); |
||
| 123 | my $swap_alloc_B = sprintf( "%d ", $swap_alloc * $PAGETOBYTE ); |
||
| 124 | my $swap_free_B = sprintf( "%d ", $swap_free * $PAGETOBYTE ); |
||
| 125 | |||
| 126 | $h_swapvalue{"Alloc.value"} = "$swap_alloc_B";
|
||
| 127 | $h_swapvalue{"Unalloc.value"} = "$swap_unalloc_B";
|
||
| 128 | $h_swapvalue{"Avail.value"} = "$swap_avail_B";
|
||
| 129 | |||
| 130 | return %h_swapvalue; |
||
| 131 | } |
||
| 132 | |||
| 133 | sub output |
||
| 134 | {
|
||
| 135 | my %h_swapvalues=value(); |
||
| 136 | print "Alloc.value " . $h_swapvalues{"Alloc.value"} . " \n";
|
||
| 137 | print "Unalloc.value " . $h_swapvalues{"Unalloc.value"} . " \n";
|
||
| 138 | print "Avail.value " . $h_swapvalues{"Avail.value"} . "\n";
|
||
| 139 | } |
||
| 140 | |||
| 141 | sub config |
||
| 142 | {
|
||
| 143 | print "graph_args --base 1024 -l 0 \n"; |
||
| 144 | print "graph_vlabel Bytes\n"; |
||
| 145 | print "graph_title Swapspace usage\n"; |
||
| 146 | print "graph_category system\n"; |
||
| 147 | print "graph_info This graph shows what the machine uses Swapspace for.\n"; |
||
| 148 | print "graph_order "; |
||
| 149 | |||
| 150 | print "Alloc ", |
||
| 151 | "Unalloc ", |
||
| 152 | "Avail ", |
||
| 153 | "\n"; |
||
| 154 | |||
| 155 | print "Alloc.label Alloc \n"; |
||
| 156 | print "Alloc.draw \n"; |
||
| 157 | print "Alloc.info Swap used.\n"; |
||
| 158 | print "Unalloc.label Unalloc \n"; |
||
| 159 | print "Unalloc.draw \n"; |
||
| 160 | print "Unalloc.info Swap reserved but not allocated.\n"; |
||
| 161 | print "Avail.label Avail \n"; |
||
| 162 | print "Avail.draw \n"; |
||
| 163 | print "Avail.info Swap available.\n"; |
||
| 164 | } |
