]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/memory.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2010 IPFire Team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
34 my %mainsettings = ();
35 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
36 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
38 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
39 $querry[0] = '' unless defined $querry[0];
40 $querry[1] = 'hour' unless defined $querry[1];
42 if ( $querry[0] =~ "memory"){
43 print "Content-type: image/png\n\n";
45 &Graphs
::updatememorygraph
($querry[1]);
46 }elsif ( $querry[0] =~ "swap"){
47 print "Content-type: image/png\n\n";
49 &Graphs
::updateswapgraph
($querry[1]);
51 &Header
::showhttpheaders
();
52 &Header
::openpage
($Lang::tr
{'memory information'}, 1, '');
53 &Header
::openbigbox
('100%', 'left');
55 &Header
::openbox
('100%', 'center', "Memory $Lang::tr{'graph'}");
56 &Graphs
::makegraphbox
("memory.cgi","memory","day");
59 if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/swap 2>/dev/null` ) {
60 &Header
::openbox
('100%', 'center', "Swap $Lang::tr{'graph'}");
61 &Graphs
::makegraphbox
("memory.cgi","swap","day");
65 &Header
::openbox
('100%', 'center', $Lang::tr
{'memory'});
66 print "<table width='95%' cellspacing='5'>";
76 open(FREE
,'/usr/bin/free |');
78 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ ){
81 <td align='center'> </td>
82 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
83 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
84 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
85 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
90 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/){
91 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
92 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
95 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
96 <td align='center'>$size KB</td>
99 }elsif($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/){
100 ($size,$used,$free) = ($1,$2,$3);
102 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
108 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
109 <td align='center'>$size KB</td>
112 }elsif($ram and $_ =~ m/^-\/\
+ buffers\
/cache:\s+(\d+)\s+(\d+)$/ ){
113 ($used,$free) = ($1,$2);
114 ($percent = ($used/$ram)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
115 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>";
118 <td align='center'>$used KB</td>
119 <td align='center'>$free KB</td>
123 &percentbar
($percent);
126 <td align='left'>$percent</td>
134 <tr><td class='boldbase' colspan='2'><br /></td></tr>
135 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='center'>$shared KB</td></tr>
136 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='center'>$buffers KB</td></tr>
137 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='center'>$cached KB</td></tr>
143 &Header
::closebigbox
();
144 &Header
::closepage
();
152 if ($percent =~ m/^(\d+)%$/ ){
154 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
158 if ($percent eq "100%"){
159 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>";
160 }elsif($percent eq "0%"){
161 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>";
163 print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>";
166 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>