]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/memory.cgi
Uploads.cgi entfernt. Die war noch ueber.
[ipfire-2.x.git] / html / cgi-bin / memory.cgi
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
11 use strict;
12
13 # enable only the following on debugging purpose
14 use warnings;
15 use CGI::Carp 'fatalsToBrowser';
16
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";
21
22 my %cgiparams=();
23
24 &Graphs::updatememgraph ("day");
25
26 &Header::showhttpheaders();
27 &Header::getcgihash(\%cgiparams);
28 &Header::openpage($Lang::tr{'memory information'}, 1, '');
29 &Header::openbigbox('100%', 'left');
30
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' />";
37 print "</a>";
38 } else {
39 print $Lang::tr{'no information available'};
40 }
41 print "<br />\n";
42 &Header::closebox();
43
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' />";
50 print "</a>";
51 } else {
52 print $Lang::tr{'no information available'};
53 }
54 print "<br />\n";
55 &Header::closebox();
56
57 &Header::openbox('100%', 'center', $Lang::tr{'memory'});
58 print "<table width='95%' cellspacing='5'>";
59 my $ram=0;
60 my $size=0;
61 my $used=0;
62 my $free=0;
63 my $percent=0;
64 my $shared=0;
65 my $buffers=0;
66 my $cached=0;
67 open(FREE,'/usr/bin/free |');
68 while(<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>
80 END
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>
90 END
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>
104 END
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>
115 END
116 ;
117 &percentbar($percent);
118 print <<END
119 </td>
120 <td align='left'>$percent</td>
121 </tr>
122 END
123 ;
124 }
125 }
126 close FREE;
127 print <<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>
133 END
134 ;
135 &Header::closebox();
136
137 &Header::closebigbox();
138
139 &Header::closepage();
140
141 sub 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>
152 END
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>
163 END
164 ;
165 }
166 }