X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fmemory.cgi;h=1708b0f3210edb905df93b7565390c21cb56ef34;hb=7b57b6f44151e64ac223524e13fc4b46d78ed1c3;hp=030afe867df07723f7b170d3f8824516b78e81a9;hpb=350b52c5c9368951ff2a9139817b42d0aec03ad7;p=people%2Fteissler%2Fipfire-2.x.git diff --git a/html/cgi-bin/memory.cgi b/html/cgi-bin/memory.cgi index 030afe867..1708b0f32 100644 --- a/html/cgi-bin/memory.cgi +++ b/html/cgi-bin/memory.cgi @@ -1,78 +1,82 @@ #!/usr/bin/perl -# -# SmoothWall CGIs -# -# This code is distributed under the terms of the GPL -# -# (c) The SmoothWall Team -# -# +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2005-2010 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### use strict; # enable only the following on debugging purpose -use warnings; -use CGI::Carp 'fatalsToBrowser'; +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; -my %cgiparams=(); +my %color = (); +my %mainsettings = (); +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); -&Graphs::updatememgraph ("day"); -&Graphs::updatememgraph ("week"); -&Graphs::updatememgraph ("month"); -&Graphs::updatememgraph ("year"); +my @querry = split(/\?/,$ENV{'QUERY_STRING'}); +$querry[0] = '' unless defined $querry[0]; +$querry[1] = 'hour' unless defined $querry[1]; -&Header::showhttpheaders(); -&Header::getcgihash(\%cgiparams); -&Header::openpage($Lang::tr{'memory information'}, 1, ''); -&Header::openbigbox('100%', 'left'); +if ( $querry[0] =~ "memory"){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updatememorygraph($querry[1]); +}elsif ( $querry[0] =~ "swap"){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updateswapgraph($querry[1]); +}else{ + &Header::showhttpheaders(); + &Header::openpage($Lang::tr{'memory information'}, 1, ''); + &Header::openbigbox('100%', 'left'); -&Header::openbox('100%', 'center', "Memory $Lang::tr{'graph'}"); -if (-e "$Header::graphdir/memory-day.png") { - my $ftime = localtime((stat("$Header::graphdir/memory-day.png"))[9]); - print "
$Lang::tr{'the statistics were last updated at'}: $ftime

\n"; - print ""; - print ""; - print ""; -} else { - print $Lang::tr{'no information available'}; -} -print "
\n"; -&Header::closebox(); + &Header::openbox('100%', 'center', "Memory $Lang::tr{'graph'}"); + &Graphs::makegraphbox("memory.cgi","memory","day"); + &Header::closebox(); -&Header::openbox('100%', 'center', "Swap $Lang::tr{'graph'}"); -if (-e "$Header::graphdir/swap-day.png") { - my $ftime = localtime((stat("$Header::graphdir/swap-day.png"))[9]); - print "
$Lang::tr{'the statistics were last updated at'}: $ftime

\n"; - print ""; - print ""; - print ""; -} else { - print $Lang::tr{'no information available'}; -} -print "
\n"; -&Header::closebox(); + if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/swap 2>/dev/null` ) { + &Header::openbox('100%', 'center', "Swap $Lang::tr{'graph'}"); + &Graphs::makegraphbox("memory.cgi","swap","day"); + &Header::closebox(); + } + + &Header::openbox('100%', 'center', $Lang::tr{'memory'}); + print ""; + my $ram=0; + my $size=0; + my $used=0; + my $free=0; + my $percent=0; + my $shared=0; + my $buffers=0; + my $cached=0; -&Header::openbox('100%', 'center', $Lang::tr{'memory'}); -print "
"; -my $ram=0; -my $size=0; -my $used=0; -my $free=0; -my $percent=0; -my $shared=0; -my $buffers=0; -my $cached=0; -open(FREE,'/usr/bin/free |'); -while() -{ - if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ ) - { - print <){ + if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ ){ + print < @@ -82,88 +86,85 @@ while() END ; - } else { - if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) { - ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6); - ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; - print < - + END ; - } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) { - ($size,$used,$free) = ($1,$2,$3); - if ($size != 0) - { - ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; - } else { - ($percent = ''); - } - print < - + END ; - } elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) { - ($used,$free) = ($1,$2); - ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; - print "" - } - print <$used - + }elsif($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ){ + ($used,$free) = ($1,$2); + ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; + print ""; + } + print <$used KB + END ; - } -} -close FREE; -print < - - - + + +
  $Lang::tr{'size'}
$Lang::tr{'ram'}$size$size KB$Lang::tr{'swap'}$size$size KB
$Lang::tr{'excluding buffers and cache'}$free
$Lang::tr{'excluding buffers and cache'}$free KB END ; - &percentbar($percent); - print < $percent

$Lang::tr{'shared'}$shared
$Lang::tr{'buffers'}$buffers
$Lang::tr{'cached'}$cached
$Lang::tr{'shared'}$shared KB
$Lang::tr{'buffers'}$buffers KB
$Lang::tr{'cached'}$cached KB
END ; -&Header::closebox(); + &Header::closebox(); -&Header::closebigbox(); - -&Header::closepage(); + &Header::closebigbox(); + &Header::closepage(); +} -sub percentbar -{ - my $percent = $_[0]; - my $fg = '#a0a0a0'; - my $bg = '#e2e2e2'; +sub percentbar{ + my $percent = $_[0]; + my $fg = '#a0a0a0'; + my $bg = '#e2e2e2'; - if ($percent =~ m/^(\d+)%$/ ) - { - print < END ; - if ($percent eq "100%") { - print "" - } elsif ($percent eq "0%") { - print "" - } else { - print "" - } - print <"; + }elsif($percent eq "0%"){ + print ""; + }else{ + print ""; + } + print < END ; - } + } }