[or-cvs] r17844: {torstatus} (ticket:124) Adding dynamic bandwidth history graph support (in torstatus/trunk: . cgi-bin/perlgraph)
kasimir at seul.org
kasimir at seul.org
Fri Jan 2 16:47:07 UTC 2009
Author: kasimir
Date: 2009-01-02 11:47:07 -0500 (Fri, 02 Jan 2009)
New Revision: 17844
Added:
torstatus/trunk/cgi-bin/perlgraph/bandwidthgraph.pl
Modified:
torstatus/trunk/tns_update.pl
Log:
(ticket:124) Adding dynamic bandwidth history graph support
Added: torstatus/trunk/cgi-bin/perlgraph/bandwidthgraph.pl
===================================================================
--- torstatus/trunk/cgi-bin/perlgraph/bandwidthgraph.pl (rev 0)
+++ torstatus/trunk/cgi-bin/perlgraph/bandwidthgraph.pl 2009-01-02 16:47:07 UTC (rev 17844)
@@ -0,0 +1,117 @@
+#!/usr/bin/perl
+#
+# plot.pl for TorStatus
+# Copyright (c) Kasimir Gabert 2009
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+# The Tor(TM) trademark and Tor Onion Logo are trademarks of The Tor Project.
+#
+# Required Perl packages:
+# * CGI from CPAN to communicate easily with requests from the web server
+# * RRDs to create the graphs
+#
+
+use CGI;
+use RRDs;
+
+my $cgi = new CGI;
+
+# Flush the buffers so RRDs will output
+$| = 1;
+
+# Determine the bandwidth file, name, and time period
+my $fp = $cgi->param('fp');
+my $name = $cgi->param('name');
+my $time = $cgi->param('time');
+
+# Ensure that there is nothing weird in the fingerprint
+if ((length $fp) != 40 || $fp =~ /[^[A-Z0-9]/)
+{
+ print "Content-type: text/html\n\n";
+ print "Unknown input.";
+ exit;
+}
+# Make sure that the date is an allowed one
+unless ($time eq "day" || $time eq "week" || $time eq "month" || $time eq "3months" || $time eq "year")
+{
+ print "Content-type: text/html\n\n";
+ print "Unknown time period.";
+ exit;
+}
+
+# Get the bwfile to create the graphs from
+my $bwfile = "../../bandwidthhistory/$fp.rrd";
+
+# Declare the common graph arguments
+my @graphargs = (
+ "--lower-limit=0",
+ "--end=now",
+ "--height=130",
+ "DEF:read=$bwfile:read:AVERAGE",
+ "DEF:write=$bwfile:write:AVERAGE",
+ "--color=BACK#FFFFFF",
+ "--color=FRAME#FFF368",
+ "--color=SHADEA#FFF368",
+ "--color=SHADEB#FFF368",
+ "--color=FONT#0000BF",
+ "--color=ARROW#000000",
+ "AREA:read#0000BF:Read History",
+ "LINE2:write#FFF368:Write History",
+ "--vertical-label=Bandwidth (KBps)",
+);
+
+my @timeargs = ();
+
+# Determine the time period
+if ($time eq "day")
+{
+ push @timeargs,
+ "--title=Past Day's Bandwidth for $name",
+ "--start=end-1d";
+}
+elsif ($time eq "week")
+{
+ push @timeargs,
+ "--title=Past Week's Bandwidth for $name",
+ "--start=end-1w";
+}
+elsif ($time eq "month")
+{
+ push @timeargs,
+ "--title=Past Month's Bandwidth for $name",
+ "--start=end-1m";
+}
+elsif ($time eq "3months")
+{
+ push @timeargs,
+ "--title=Past Three Month's Bandwidth for $name",
+ "--start=end-3m";
+}
+elsif ($time eq "year")
+{
+ push @timeargs,
+ "--title=Past Year's Bandwidth for $name",
+ "--start=end-1y";
+}
+
+
+# Output the graph
+print "Content-type: image/png\n\n";
+RRDs::graph(
+ "-",
+ @timeargs,
+ @graphargs
+);
+
Property changes on: torstatus/trunk/cgi-bin/perlgraph/bandwidthgraph.pl
___________________________________________________________________
Name: svn:executable
+ *
Modified: torstatus/trunk/tns_update.pl
===================================================================
--- torstatus/trunk/tns_update.pl 2009-01-02 02:46:48 UTC (rev 17843)
+++ torstatus/trunk/tns_update.pl 2009-01-02 16:47:07 UTC (rev 17844)
@@ -698,7 +698,7 @@
# Update the read and write bandwidth history
# Only do this once every 900*10 seconds to retain
# speed, and more frequent updates are not necessary
- if ($config{'BandwidthHistory'} eq "true" && $updateCounter % 10 == 1)
+ if ($config{'BandwidthHistory'} eq "true" && $updateCounter % 5 == 1)
{
updateBandwidth( $currentRouter{'Fingerprint'},
$currentRouter{'write'},
@@ -1261,7 +1261,6 @@
# Determine whether a bandwidth history file for this router exists
my $bwfile = $config{'TNS_Path'} . "bandwidthhistory/$fingerprint.rrd";
- my $graphfile = $config{'TNS_Path'} . "web/bandwidthgraph/$fingerprint";
unless (-e $bwfile)
{
@@ -1323,58 +1322,4 @@
print "RRDs::update error: $err\n" if $err;
}
}
- # Declare the common graph arguments
- my @graphargs = (
- "--lower-limit=0",
- "--end=now",
- "--height=130",
- "DEF:read=$bwfile:read:AVERAGE",
- "DEF:write=$bwfile:write:AVERAGE",
- "--color=BACK#FFFFFF",
- "--color=FRAME#FFF368",
- "--color=SHADEA#FFF368",
- "--color=SHADEB#FFF368",
- "--color=FONT#0000BF",
- "--color=ARROW#000000",
- "AREA:read#0000BF:Read History",
- "LINE2:write#FFF368:Write History"
- );
-
- # Create a new RRD graph for the router
- RRDs::graph(
- $graphfile . "_y.png",
- "--title=Past Year's Bandwidth for $name",
- "--vertical-label=Bandwidth (KBps)",
- "--start=end-1y",
- @graphargs
- );
- RRDs::graph(
- $graphfile . "_3m.png",
- "--title=Past Three Month's Bandwidth for $name",
- "--vertical-label=Bandwidth (KBps)",
- "--start=end-3m",
- @graphargs
- );
- RRDs::graph(
- $graphfile . "_m.png",
- "--title=Past Month's Bandwidth for $name",
- "--vertical-label=Bandwidth (KBps)",
- "--start=end-1m",
- @graphargs
- );
- RRDs::graph(
- $graphfile . "_w.png",
- "--title=Past Week's Bandwidth for $name",
- "--vertical-label=Bandwidth (KBps)",
- "--start=end-1w",
- @graphargs
- );
- RRDs::graph(
- $graphfile . "_d.png",
- "--title=Past Day's Bandwidth for $name",
- "--vertical-label=Bandwidth (KBps)",
- "--start=end-1d",
- @graphargs
- );
-
}
More information about the tor-commits
mailing list