File: swap.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (100 lines) | stat: -rwxr-xr-x 2,528 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!@@PERL@@
#
# Developed 05/28/2003 by Mike Discenza
# mike.discenza@dillards.com
#
# $Log$
# Revision 1.1  2004/01/02 18:50:00  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.2  2003/11/07 17:43:16  jimmyo
# Cleanups and log entries
#
#
#
#
# Plugin to monitor memory usage on AIX.
#
#   DESCRIPTION
#   ===========
#      This will measure the total amount of swap/paging space available
#      on the server, and will also measure how much of that swap space
#      is being used.  It uses /usr/sbin/lsps to find all this out.  If
#      you have more than one paging space they will be added together,
#      so will the total amount of space used.  This is the total amount
#      used after all.
#      
#   RESTRICTIONS
#   ============
#      None known.  Should be able to run as anyone.
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - only used by munin-config)
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#%# family=contrib
#%# capabilities=autoconf

use strict;
use POSIX;

if($ARGV[0] && $ARGV[0] eq "autoconf")
  {
    if(-e "/usr/sbin/lsps" && -X "/usr/sbin/lsps")
      {
        print "yes\n";
        exit 0;
      }
    else
      {
        print "no\n";
        exit 1;
      }
  }

if($ARGV[0] && $ARGV[0] eq "config")
  {
    print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit ".getTotalSwapBytes()."\n";
    print "graph_title Swap usage\n";
    print "graph_order used total\n";
    print "used.label used\n";
    print "used.draw STACK\n";
    print "total.label total\n";
    print "total.draw AREA\n";
    exit 0
  }

my(@swapInfo) = getSwapSpace();
print "total.value $swapInfo[0]\n";
print "used.value $swapInfo[1]\n";
  
sub getSwapSpace
{
  my($line,@lineArray,$amountUsed,$totalSpace);
  open SWAPINFO, "/usr/sbin/lsps -a|tail +2|";
  while($line = <SWAPINFO>)
    {
      @lineArray = split(/ +/,$line);
      $totalSpace += (substr($lineArray[3],0,-2) * 1024) * 1024;
      $amountUsed += ((substr($lineArray[3],0,-2) * ($lineArray[4]/100)) * 1024) * 1024;
    }
  return (ceil($totalSpace),ceil($amountUsed));
}

sub getTotalSwapBytes
{
  my($line,@lineArray,$totalSpace);
  open SWAPINFO, "/usr/sbin/lsps -a|tail +2|";
  while($line = <SWAPINFO>)
    {
      @lineArray = split(/ +/,$line);
      $totalSpace += (substr($lineArray[3],0,-2) * 1024) * 1024;
    }
  return (ceil($totalSpace));
}