]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/memory.cgi
Am Pakfire weitergearbeitet.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / memory.cgi
CommitLineData
72fe12a9
MT
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9#
10
11use strict;
12
13# enable only the following on debugging purpose
14use warnings;
15use CGI::Carp 'fatalsToBrowser';
16
17require '/var/ipfire/general-functions.pl';
18require "${General::swroot}/lang.pl";
19require "${General::swroot}/header.pl";
350b52c5 20require "${General::swroot}/graphs.pl";
72fe12a9
MT
21
22my %cgiparams=();
23
350b52c5 24&Graphs::updatememgraph ("day");
72fe12a9 25
350b52c5 26&Header::showhttpheaders();
72fe12a9 27&Header::getcgihash(\%cgiparams);
72fe12a9 28&Header::openpage($Lang::tr{'memory information'}, 1, '');
72fe12a9
MT
29&Header::openbigbox('100%', 'left');
30
31&Header::openbox('100%', 'center', "Memory $Lang::tr{'graph'}");
32if (-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' />";
37 print "</a>";
38} else {
39 print $Lang::tr{'no information available'};
40}
41print "<br />\n";
42&Header::closebox();
43
44&Header::openbox('100%', 'center', "Swap $Lang::tr{'graph'}");
45if (-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' />";
50 print "</a>";
51} else {
52 print $Lang::tr{'no information available'};
53}
54print "<br />\n";
55&Header::closebox();
56
57&Header::openbox('100%', 'center', $Lang::tr{'memory'});
58print "<table width='95%' cellspacing='5'>";
59my $ram=0;
60my $size=0;
61my $used=0;
62my $free=0;
63my $percent=0;
64my $shared=0;
65my $buffers=0;
66my $cached=0;
67open(FREE,'/usr/bin/free |');
68while(<FREE>)
69{
70 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
71 {
72 print <<END
73<tr>
74<td align='center'>&nbsp;</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>
79</tr>
80END
81;
82 } else {
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%/;
86 print <<END
87<tr>
88<td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
89<td align='center'>$size</td>
90END
91;
92 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
93 ($size,$used,$free) = ($1,$2,$3);
94 if ($size != 0)
95 {
96 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
97 } else {
98 ($percent = '');
99 }
100 print <<END
101<tr>
102<td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
103<td align='center'>$size</td>
104END
105;
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>"
110 }
111 print <<END
112<td align='center'>$used</td>
113<td align='center'>$free</td>
114<td>
115END
116;
117 &percentbar($percent);
118 print <<END
119</td>
120<td align='left'>$percent</td>
121</tr>
122END
123;
124 }
125}
126close FREE;
127print <<END
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>
132</table>
133END
134;
135&Header::closebox();
136
137&Header::closebigbox();
138
139&Header::closepage();
140
141sub percentbar
142{
143 my $percent = $_[0];
144 my $fg = '#a0a0a0';
145 my $bg = '#e2e2e2';
146
147 if ($percent =~ m/^(\d+)%$/ )
148 {
149 print <<END
150<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
151<tr>
152END
153;
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'>"
158 } else {
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'>"
160 }
161 print <<END
162<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
163END
164;
165 }
166}