makegraphs umgebaut, sodass nurnoch rrd daten geschrieben werden die graphen
[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
CS
24&Graphs::updatememgraph ("day");
25&Graphs::updatememgraph ("week");
26&Graphs::updatememgraph ("month");
27&Graphs::updatememgraph ("year");
72fe12a9 28
350b52c5 29&Header::showhttpheaders();
72fe12a9 30&Header::getcgihash(\%cgiparams);
72fe12a9 31&Header::openpage($Lang::tr{'memory information'}, 1, '');
72fe12a9
MT
32&Header::openbigbox('100%', 'left');
33
34&Header::openbox('100%', 'center', "Memory $Lang::tr{'graph'}");
35if (-e "$Header::graphdir/memory-day.png") {
36 my $ftime = localtime((stat("$Header::graphdir/memory-day.png"))[9]);
37 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
38 print "<a href='/cgi-bin/graphs.cgi?graph=memory'>";
39 print "<img alt='' src='/graphs/memory-day.png' border='0' />";
40 print "</a>";
41} else {
42 print $Lang::tr{'no information available'};
43}
44print "<br />\n";
45&Header::closebox();
46
47&Header::openbox('100%', 'center', "Swap $Lang::tr{'graph'}");
48if (-e "$Header::graphdir/swap-day.png") {
49 my $ftime = localtime((stat("$Header::graphdir/swap-day.png"))[9]);
50 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
51 print "<a href='/cgi-bin/graphs.cgi?graph=swap'>";
52 print "<img alt='' src='/graphs/swap-day.png' border='0' />";
53 print "</a>";
54} else {
55 print $Lang::tr{'no information available'};
56}
57print "<br />\n";
58&Header::closebox();
59
60&Header::openbox('100%', 'center', $Lang::tr{'memory'});
61print "<table width='95%' cellspacing='5'>";
62my $ram=0;
63my $size=0;
64my $used=0;
65my $free=0;
66my $percent=0;
67my $shared=0;
68my $buffers=0;
69my $cached=0;
70open(FREE,'/usr/bin/free |');
71while(<FREE>)
72{
73 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
74 {
75 print <<END
76<tr>
77<td align='center'>&nbsp;</td>
78<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
79<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
80<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
81<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
82</tr>
83END
84;
85 } else {
86 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
87 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
88 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
89 print <<END
90<tr>
91<td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
92<td align='center'>$size</td>
93END
94;
95 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
96 ($size,$used,$free) = ($1,$2,$3);
97 if ($size != 0)
98 {
99 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
100 } else {
101 ($percent = '');
102 }
103 print <<END
104<tr>
105<td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
106<td align='center'>$size</td>
107END
108;
109 } elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) {
110 ($used,$free) = ($1,$2);
111 ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
112 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
113 }
114 print <<END
115<td align='center'>$used</td>
116<td align='center'>$free</td>
117<td>
118END
119;
120 &percentbar($percent);
121 print <<END
122</td>
123<td align='left'>$percent</td>
124</tr>
125END
126;
127 }
128}
129close FREE;
130print <<END
131<tr><td class='boldbase' colspan='2'><br /></td></tr>
132<tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='center'>$shared</td></tr>
133<tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='center'>$buffers</td></tr>
134<tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='center'>$cached</td></tr>
135</table>
136END
137;
138&Header::closebox();
139
140&Header::closebigbox();
141
142&Header::closepage();
143
144sub percentbar
145{
146 my $percent = $_[0];
147 my $fg = '#a0a0a0';
148 my $bg = '#e2e2e2';
149
150 if ($percent =~ m/^(\d+)%$/ )
151 {
152 print <<END
153<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
154<tr>
155END
156;
157 if ($percent eq "100%") {
158 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
159 } elsif ($percent eq "0%") {
160 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
161 } else {
162 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'>"
163 }
164 print <<END
165<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
166END
167;
168 }
169}