r3812 - trunk/varnish-tools/webgui/Varnish

petter at projects.linpro.no petter at projects.linpro.no
Mon Feb 23 13:44:13 CET 2009


Author: petter
Date: 2009-02-23 13:44:13 +0100 (Mon, 23 Feb 2009)
New Revision: 3812

Modified:
   trunk/varnish-tools/webgui/Varnish/DB.pm
   trunk/varnish-tools/webgui/Varnish/Statistics.pm
Log:
Fetching ALL the columns when generating graphs is stupid and time consuming. Now we only fetch the required fields.


Modified: trunk/varnish-tools/webgui/Varnish/DB.pm
===================================================================
--- trunk/varnish-tools/webgui/Varnish/DB.pm	2009-02-23 11:31:08 UTC (rev 3811)
+++ trunk/varnish-tools/webgui/Varnish/DB.pm	2009-02-23 12:44:13 UTC (rev 3812)
@@ -56,7 +56,7 @@
 					push @field_values, $value;
 				}
 				else {
-					print STDERR "Field $db_field does not exist in the stat table. Please update schema\n";
+					print STDERR "Field $db_field does not exist in the stat table. Please update schema by running create_db_data.pl\n";
 				}
 			}
 		}
@@ -71,21 +71,25 @@
 	}
 
 	sub get_stat_data {
-		my ($self, $unit, $after_timestamp) = @_;
+		my ($self, $unit, $after_timestamp, $stat_fields_ref) = @_;
 
+		if (!defined($stat_fields_ref)) {
+			my @stat_fields = keys(%stat_field_exist);
+
+			$stat_fields_ref = \@stat_fields;
+		}
+
 		my $sql;
 		if (ref($unit) eq "Varnish::Node") {
 			$sql = "SELECT time, has_data";
-			my @stat_fields = keys %stat_field_exist;
-			for my $stat_field (@stat_fields) {
+			for my $stat_field (@$stat_fields_ref) {
 				$sql .=", $stat_field";
 			}
 			$sql .= " FROM stat WHERE node_id = ? AND time > ? ORDER BY time ASC";
 		}
 		else {
 			$sql = "SELECT time, SUM(has_data) as has_data";
-			my @stat_fields = keys %stat_field_exist;
-			for my $stat_field (@stat_fields) {
+			for my $stat_field (@$stat_fields_ref) {
 				$sql .=", SUM($stat_field) AS $stat_field";
 			}
 			$sql .= " FROM stat WHERE node_id IN (SELECT id FROM node WHERE group_id = ?) AND time >= ? GROUP BY time ORDER BY time ASC";

Modified: trunk/varnish-tools/webgui/Varnish/Statistics.pm
===================================================================
--- trunk/varnish-tools/webgui/Varnish/Statistics.pm	2009-02-23 11:31:08 UTC (rev 3811)
+++ trunk/varnish-tools/webgui/Varnish/Statistics.pm	2009-02-23 12:44:13 UTC (rev 3812)
@@ -55,6 +55,12 @@
 			return (undef, undef);
 		}
 	}
+
+	sub _union {
+		my %temp_hash = map { $_ => 1 } @_;
+
+		return keys %temp_hash;
+	}
 	
 	sub generate_graph_data {
 		my ($self, $unit_id, $is_node, $time_span, $divisors_ref, $dividends_ref, $use_delta, $desired_number_of_values) = @_;
@@ -73,23 +79,26 @@
 		if ($use_delta) {
 			$start_time -= $poll_interval;
 		}
+
+		my @divisors = ($divisors_ref ? 
+							map {  get_db_friendly_name($_); } @$divisors_ref : ());
+		my @dividends = ($dividends_ref ? 
+							map {  get_db_friendly_name($_); } @$dividends_ref : ());
+		my @all_fields = _union(@dividends, @divisors);
 	
 		my $measures_ref;
 		if ($is_node) {
 			my $node = Varnish::NodeManager->get_node($unit_id);
 			return ([],[], -1, -1) if (!$node);
-			$measures_ref = Varnish::DB->get_stat_data($node, $start_time);
+			$measures_ref = Varnish::DB->get_stat_data($node, $start_time, \@all_fields);
 		}
 		else {
 			my $group = Varnish::NodeManager->get_group($unit_id);
 			return ([],[], -1, -1) if (!$group);
-			$measures_ref = Varnish::DB->get_stat_data($group, $start_time);
+			$measures_ref = Varnish::DB->get_stat_data($group, $start_time, \@all_fields);
 		}
 
-		my @divisors = ($divisors_ref ? 
-							map {  get_db_friendly_name($_); } @$divisors_ref : ());
-		my @dividends = ($dividends_ref ? 
-							map {  get_db_friendly_name($_); } @$dividends_ref : ());
+
 		my @values;
 		my @times;
 		my $value2;



More information about the varnish-commit mailing list