/
swap.in
92 lines (73 loc) · 2.04 KB
/
swap.in
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
#!@@PERL@@
# -*- perl -*-
=head1 NAME
swap - Plugin to monitor memory usage on AIX
=head1 COFIGURATION
No configuration
=head1 NOTES
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.
=head1 AUTHOR
Developed 05/28/2003 by Mike Discenza <mike.discenza@dillards.com>
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=contrib
#%# capabilities=autoconf
=cut
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 0;
}
}
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 "graph_category system\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));
}