From: petter Date: Mon, 23 Feb 2009 12:44:13 +0000 (+0000) Subject: Fetching ALL the columns when generating graphs is stupid and time consuming. Now... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63ec5f7185b4a2c07a69ef470f51110b6f6d34b6;p=varnish Fetching ALL the columns when generating graphs is stupid and time consuming. Now we only fetch the required fields. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3812 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/webgui/Varnish/DB.pm b/varnish-tools/webgui/Varnish/DB.pm index d03df496..97545ce8 100644 --- a/varnish-tools/webgui/Varnish/DB.pm +++ b/varnish-tools/webgui/Varnish/DB.pm @@ -56,7 +56,7 @@ use Varnish::DB_Data; 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 @@ use Varnish::DB_Data; } 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"; diff --git a/varnish-tools/webgui/Varnish/Statistics.pm b/varnish-tools/webgui/Varnish/Statistics.pm index 328af350..589fddb4 100644 --- a/varnish-tools/webgui/Varnish/Statistics.pm +++ b/varnish-tools/webgui/Varnish/Statistics.pm @@ -55,6 +55,12 @@ use Varnish::DB; 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 @@ use Varnish::DB; 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;