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";
}
}
}
}
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";
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) = @_;
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;