]> err.no Git - varnish/commitdiff
Fetching ALL the columns when generating graphs is stupid and time consuming. Now...
authorpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 23 Feb 2009 12:44:13 +0000 (12:44 +0000)
committerpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 23 Feb 2009 12:44:13 +0000 (12:44 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3812 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-tools/webgui/Varnish/DB.pm
varnish-tools/webgui/Varnish/Statistics.pm

index d03df4963e197e1bfe35b203d5436c1bda3c4171..97545ce843e40c1b374953dd719c305d0fc7631e 100644 (file)
@@ -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";
index 328af350bf90b21c34825f8bb2af8fcfd8a63593..589fddb433fd12151ad1418b4297e07df3f98659 100644 (file)
@@ -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;