contrib/collection3: Add the "IgnoreUnknown" config option.
[collectd.git] / contrib / collection3 / lib / Collectd / Graph / Type / GenericStacked.pm
index 273d89e..ab95ee2 100644 (file)
@@ -32,11 +32,36 @@ sub getRRDArgs
   my $idents = $group->{$group[$index]};
   my $ds_name_len = 0;
 
+  my $ds = $obj->getDataSources ();
+  if (!$ds)
+  {
+    confess ("obj->getDataSources failed.");
+  }
+  if (@$ds != 1)
+  {
+    confess ("I can only work with RRD files that have "
+      . "exactly one data source!");
+  }
+  my $data_source = $ds->[0];
+
   my $rrd_title = $obj->getTitle ($idents->[0]);
 
   my $colors = $obj->{'rrd_colors'} || {};
   my @ret = ('-t', $rrd_title, @$rrd_opts);
 
+  my $ignore_unknown = $obj->{'ignore_unknown'} || 0;
+  if ($ignore_unknown)
+  {
+    if ($ignore_unknown =~ m/^(yes|true|on)$/i)
+    {
+      $ignore_unknown = 1;
+    }
+    else
+    {
+      $ignore_unknown = 0;
+    }
+  }
+
   if (defined $obj->{'rrd_vertical'})
   {
     push (@ret, '-v', $obj->{'rrd_vertical'});
@@ -47,6 +72,23 @@ sub getRRDArgs
     sort_idents_by_type_instance ($idents, $obj->{'custom_order'});
   }
 
+  if ($ignore_unknown)
+  {
+    my $new_idents = [];
+    for (@$idents)
+    {
+      if (exists ($obj->{'ds_names'}{$_->{'type_instance'}}))
+      {
+       push (@$new_idents, $_);
+      }
+    }
+
+    if (@$new_idents)
+    {
+      $idents = $new_idents;
+    }
+  }
+
   $obj->{'ds_names'} ||= {};
   my @names = map { $obj->{'ds_names'}{$_->{'type_instance'}} || $_->{'type_instance'} } (@$idents);
 
@@ -64,9 +106,9 @@ sub getRRDArgs
     $names[$i] =~ s/:/\\:/g;
 
     push (@ret,
-      "DEF:min${i}=${filename}:value:MIN",
-      "DEF:avg${i}=${filename}:value:AVERAGE",
-      "DEF:max${i}=${filename}:value:MAX");
+      "DEF:min${i}=${filename}:${data_source}:MIN",
+      "DEF:avg${i}=${filename}:${data_source}:AVERAGE",
+      "DEF:max${i}=${filename}:${data_source}:MAX");
   }
 
   for (my $i = @$idents - 1; $i >= 0; $i--)