]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/memory.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
13 # enable only the following on debugging purpose
15 use CGI
::Carp
'fatalsToBrowser';
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
20 require "${General::swroot}/graphs.pl";
24 &Graphs
::updatememgraph
("day");
26 &Header
::showhttpheaders
();
27 &Header
::getcgihash
(\
%cgiparams);
28 &Header
::openpage
($Lang::tr
{'memory information'}, 1, '');
29 &Header
::openbigbox
('100%', 'left');
31 &Header
::openbox
('100%', 'center', "Memory $Lang::tr{'graph'}");
32 if (-e
"$Header::graphdir/memory-day.png") {
33 my $ftime = localtime((stat("$Header::graphdir/memory-day.png"))[9]);
34 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
35 print "<a href='/cgi-bin/graphs.cgi?graph=memory'>";
36 print "<img alt='' src='/graphs/memory-day.png' border='0' />";
39 print $Lang::tr
{'no information available'};
44 &Header
::openbox
('100%', 'center', "Swap $Lang::tr{'graph'}");
45 if (-e
"$Header::graphdir/swap-day.png") {
46 my $ftime = localtime((stat("$Header::graphdir/swap-day.png"))[9]);
47 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
48 print "<a href='/cgi-bin/graphs.cgi?graph=swap'>";
49 print "<img alt='' src='/graphs/swap-day.png' border='0' />";
52 print $Lang::tr
{'no information available'};
57 &Header
::openbox
('100%', 'center', $Lang::tr
{'memory'});
58 print "<table width='95%' cellspacing='5'>";
67 open(FREE
,'/usr/bin/free |');
70 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
74 <td align='center'> </td>
75 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
76 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
77 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
78 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
83 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
84 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
85 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
88 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
89 <td align='center'>$size</td>
92 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
93 ($size,$used,$free) = ($1,$2,$3);
96 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
102 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
103 <td align='center'>$size</td>
106 } elsif ($ram and $_ =~ m/^-\/\
+ buffers\
/cache:\s+(\d+)\s+(\d+)$/ ) {
107 ($used,$free) = ($1,$2);
108 ($percent = ($used/$ram)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
109 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
112 <td align='center'>$used</td>
113 <td align='center'>$free</td>
117 &percentbar
($percent);
120 <td align='left'>$percent</td>
128 <tr><td class='boldbase' colspan='2'><br /></td></tr>
129 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='center'>$shared</td></tr>
130 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='center'>$buffers</td></tr>
131 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='center'>$cached</td></tr>
137 &Header
::closebigbox
();
139 &Header
::closepage
();
147 if ($percent =~ m/^(\d+)%$/ )
150 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
154 if ($percent eq "100%") {
155 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
156 } elsif ($percent eq "0%") {
157 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
159 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'>"
162 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>