Revision: 7462
          http://sourceforge.net/p/ipcop/svn/7462
Author:   owes
Date:     2014-04-11 16:21:41 +0000 (Fri, 11 Apr 2014)
Log Message:
-----------
Replace squid-graphs with our own graphs. Does not require logging activated. 
After some longer testing add new translation texts.

Modified Paths:
--------------
    ipcop/trunk/html/cgi-bin/proxygraphs.cgi
    ipcop/trunk/src/scripts/makegraphs.pl
    ipcop/trunk/updates/2.1.5/ROOTFILES.i486-2.1.5

Modified: ipcop/trunk/html/cgi-bin/proxygraphs.cgi
===================================================================
--- ipcop/trunk/html/cgi-bin/proxygraphs.cgi    2014-04-11 16:18:49 UTC (rev 
7461)
+++ ipcop/trunk/html/cgi-bin/proxygraphs.cgi    2014-04-11 16:21:41 UTC (rev 
7462)
@@ -17,47 +17,102 @@
 #use CGI::Carp 'fatalsToBrowser';
 
 require '/usr/lib/ipcop/general-functions.pl';
-require "/usr/lib/ipcop/lang.pl";
-require "/usr/lib/ipcop/header.pl";
+require '/usr/lib/ipcop/lang.pl';
+require '/usr/lib/ipcop/header.pl';
 
+my %cgiparams=();
+my @cgigraphs=();
 my @graphs = ();
+my $graphdir = '/home/httpd/html/graphs';
 
 &Header::showhttpheaders();
 
-my $dir       = "/home/httpd/html/sgraph";
-my $sgraphdir = "/home/httpd/html/sgraph";
+$ENV{'QUERY_STRING'} =~ s/&//g;
+@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
+$cgigraphs[1] = '' unless defined $cgigraphs[1];
 
 &Header::openpage($Lang::tr{'proxy access graphs'}, 1, '');
 
 &Header::openbigbox('100%', 'left');
 
-&Header::openbox('100%', 'left', $Lang::tr{'proxy access graphs'});
+if ($cgigraphs[1] =~ /(squid-requests|squid-hits)/) {
+    # Display 1 specific graph
 
-if (open(IPACHTML, "$sgraphdir/index.html")) {
-    my $skip = 1;
-    while (<IPACHTML>) {
-        $skip = 1 if /^<HR>$/;
-        if ($skip) {
-            $skip = 0 if /<H1>/;
-            next;
-        }
-        s/<IMG SRC=([^"'>]+)>/<img src='\/sgraph\/$1' alt='Graph' \/>/;
-        s/<HR>/<hr \/>/g;
-        s/<BR>/<br \/>/g;
-        s/<([^>]*)>/\L<$1>\E/g;
-        s/(size|align|border|color)=([^'"> ]+)/$1='$2'/g;
-        # strip out size=-1 from font tags
-        s/ size=\'-1\'//g;
-        print;
+    my $graph = $cgigraphs[1];
+    my ($graphname, $count) = split('_', lc($graph));
+    my $back = '';
+    my $title = '';
+    $title = $Lang::tr{'squid requests'} if ($graph eq 'squid-requests');
+    $title = $Lang::tr{'squid hits'} if ($graph eq 'squid-hits');
+
+    &Header::openbox('100%', 'center', "$title $Lang::tr{'graph'}");
+
+    if (-e "$graphdir/${graph}-day.png") {
+        print <<END
+<table width='100%'><tr>
+    <td width='10%'><a href='/cgi-bin/proxygraphs.cgi'><img 
src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' 
/></a></td>
+    <td>&nbsp;</td>
+</tr></table>
+<hr />
+<img src='/graphs/${graph}-day.png' border='0' alt='${graph}-$Lang::tr{'day'}' 
/><hr />
+<img src='/graphs/${graph}-week.png' border='0' 
alt='${graph}-$Lang::tr{'week'}' /><hr />
+<img src='/graphs/${graph}-month.png' border='0' 
alt='${graph}-$Lang::tr{'month'}' /><hr />
+<img src='/graphs/${graph}-year.png' border='0' 
alt='${graph}-$Lang::tr{'year'}' />
+END
+        ;
+    } 
+    else {
+        print $Lang::tr{'no information available'};
     }
-    close(IPACHTML);
+
+    print <<END
+<hr />
+<table width='100%'><tr>
+    <td width='10%'><a href='/cgi-bin/proxygraphs.cgi'><img 
src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' 
/></a></td>
+    <td>&nbsp;</td>
+</tr></table>
+END
+    ;
+    &Header::closebox();
 }
 else {
-    print $Lang::tr{'no information available'};
+    &disp_graph("$Lang::tr{'proxy access graphs'}", "squid-requests", 
"squid-requests-$Lang::tr{'day'}");
+    &disp_graph("$Lang::tr{'proxy access graphs'}", "squid-hits", 
"squid-hits-$Lang::tr{'day'}");
 }
 
-&Header::closebox();
-
 &Header::closebigbox();
 
 &Header::closepage();
+
+
+sub disp_graph
+{
+    my $title = shift;
+    my $file  = shift;
+    my $alt   = shift;
+
+    &Header::openbox('100%', 'center', $title);
+    if (-e "$graphdir/$file-day.png") {
+        print "<a href='/cgi-bin/proxygraphs.cgi?graph=$file'>";
+        print "<img src='/graphs/$file-day.png' alt='$alt' border='0' />";
+        print "</a><br />";
+    } else {
+        print $Lang::tr{'no information available'};
+    }
+
+    if ( $file eq 'cpu' ) {
+        print<<END
+<table width='100%'>
+<tr>
+    <td class='comment1button'>&nbsp;</td>
+    <td class='button1button'>&nbsp;</td>
+    <td class='onlinehelp'>
+        <a href='${General::adminmanualurl}/status-proxy-graphs.html' 
target='_blank'><img src='/images/web-support.png' alt='$Lang::tr{'online help 
en'}' title='$Lang::tr{'online help en'}' /></a>
+    </td>
+</tr>
+</table>
+END
+        ;
+    }
+    &Header::closebox();
+}

Modified: ipcop/trunk/src/scripts/makegraphs.pl
===================================================================
--- ipcop/trunk/src/scripts/makegraphs.pl       2014-04-11 16:18:49 UTC (rev 
7461)
+++ ipcop/trunk/src/scripts/makegraphs.pl       2014-04-11 16:21:41 UTC (rev 
7462)
@@ -353,7 +353,7 @@
             "$rrdlog/diskuse.rrd",      "--step=300",
             "DS:root:GAUGE:600:0:1000", "DS:varlog:GAUGE:600:0:1000",
             "RRA:AVERAGE:0.5:1:576",   "RRA:AVERAGE:0.5:6:672",
-           "RRA:AVERAGE:0.5:24:732",   "RRA:AVERAGE:0.5:144:1460"
+            "RRA:AVERAGE:0.5:24:732",  "RRA:AVERAGE:0.5:144:1460"
         );
         $ERROR = RRDs::error;
         print "Error in RRD::create for diskuse: $ERROR\n" if $ERROR;
@@ -495,11 +495,59 @@
     print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
 }
 
+sub updatesquidgraph {
+    my $period = $_[0];
+    my @rrd = ();
+
+    push @rrd, @{&rrd_header("squid-requests", $period, "proxy requests 
($Lang::tr{$period})", -1, -1)};
+
+    push @rrd, "DEF:requests=$rrdlog/squid_requests.rrd:requests:AVERAGE";
+    push @rrd, "LINE2:requests#00FF00:proxy requests per second\\j";
+    push @rrd, "GPRINT:requests:MAX:$Lang::tr{'maximal'}\\:%8.0lf";
+    push @rrd, "GPRINT:requests:AVERAGE:$Lang::tr{'average'}\\:%8.0lf";
+    push @rrd, "GPRINT:requests:LAST:$Lang::tr{'current'}\\:%8.0lf\\j";
+
+    push @rrd, @{&rrd_lastupdate()};
+    RRDs::graph (@rrd);
+
+    $ERROR = RRDs::error;
+    print "Error in RRD::graph for squid requests: $ERROR\n" if $ERROR;
+
+    @rrd = ();
+
+    push @rrd, @{&rrd_header("squid-hits", $period, "hits percentage 
($Lang::tr{$period})", -1, -1)};
+
+    push @rrd, "DEF:hits_per=$rrdlog/squid_requests.rrd:hits_per:AVERAGE";
+    push @rrd, "LINE2:hits_per#00FF00:hits percentage\\j";
+    push @rrd, "GPRINT:hits_per:MAX:$Lang::tr{'maximal'}\\:%8.0lf";
+    push @rrd, "GPRINT:hits_per:AVERAGE:$Lang::tr{'average'}\\:%8.0lf";
+    push @rrd, "GPRINT:hits_per:LAST:$Lang::tr{'current'}\\:%8.0lf\\j";
+
+    push @rrd, @{&rrd_lastupdate()};
+    RRDs::graph (@rrd);
+
+    $ERROR = RRDs::error;
+    print "Error in RRD::graph for squid hits: $ERROR\n" if $ERROR;
+}
+
 sub updatesquiddata {
     my $sock;
     my $host = "127.0.0.1";
     my $port = "82";
 
+    if (!-e "$rrdlog/squid_requests.rrd") {
+        RRDs::create(
+            "$rrdlog/squid_requests.rrd",
+            "--step=300",
+            "DS:requests:DERIVE:600:0:U",
+            "DS:hits_per:GAUGE:600:0:U",
+            "RRA:AVERAGE:0.5:1:576",                "RRA:AVERAGE:0.5:6:672",
+            "RRA:AVERAGE:0.5:24:732",               "RRA:AVERAGE:0.5:144:1460"
+        );
+        $ERROR = RRDs::error;
+        print "Error in RRD::create for squid requests: $ERROR\n" if $ERROR;
+    }
+
     if (!($sock = IO::Socket::INET->new(PeerAddr => scalar($host), PeerPort => 
$port, Proto => 'tcp'))) {
         print "Could not connect to proxy manager. Proxy probably disabled.\n";
         return;
@@ -509,21 +557,23 @@
     my @result = <$sock>;
     close $sock;
 
+    my %vals;
     open(FILE, ">/var/log/squid/info");
     foreach(@result) {
         print FILE $_;
+        $vals{requests} = $1 if (/Number of HTTP requests received:\s+(\d+)/);
+        $vals{hits_per} = $1 if (/Hits as % of all 
requests:\s+5min:\s+([^%]+)%,\s+60min:\s+([^%]+)%/);
     }
     close(FILE);
-}
 
+#    print "$vals{requests} $vals{hits_per}\n";
 
-###
-### Squid Graphs
-###
-if (-e "/var/log/squid/access.log") {
-    system("/usr/bin/squid-graph -o=/home/httpd/html/sgraph --tcp-only < 
/var/log/squid/access.log >/dev/null 2>&1");
+    RRDs::update("$rrdlog/squid_requests.rrd", "-t", "requests:hits_per", 
"N:$vals{requests}:$vals{hits_per}");
+    $ERROR = RRDs::error;
+    print "Error in RRD::update for squid: $ERROR\n" if $ERROR;
 }
 
+
 ###
 ### utf8 conversion
 ###
@@ -622,3 +672,8 @@
 }
 
 updatesquiddata();
+updatesquidgraph("hour");
+updatesquidgraph("day");
+updatesquidgraph("week");
+updatesquidgraph("month");
+updatesquidgraph("year");

Modified: ipcop/trunk/updates/2.1.5/ROOTFILES.i486-2.1.5
===================================================================
--- ipcop/trunk/updates/2.1.5/ROOTFILES.i486-2.1.5      2014-04-11 16:18:49 UTC 
(rev 7461)
+++ ipcop/trunk/updates/2.1.5/ROOTFILES.i486-2.1.5      2014-04-11 16:21:41 UTC 
(rev 7462)
@@ -3,6 +3,7 @@
 /home/httpd/cgi-bin/ddns.cgi
 /home/httpd/cgi-bin/index.cgi
 /home/httpd/cgi-bin/iptablesgui.cgi
+/home/httpd/cgi-bin/proxygraphs.cgi
 /home/httpd/cgi-bin/upload.cgi
 /usr/local/bin/makegraphs.pl
 /usr/local/bin/upgrade.sh

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to