Code

collection3: Add the possibility to scale generic graphs.
[collectd.git] / contrib / collection3 / lib / Collectd / Graph / Type.pm
index 60097e5c43653c8e2cd3aedabceb8bc877236dfe..01c2417c39db7bab0e5a74fbd6f91b4724e7c60a 100644 (file)
@@ -248,6 +248,20 @@ sub getTitle
   my $plugin_instance = $ident->{'plugin_instance'};
   my $type = $ident->{'type'};
   my $type_instance = $ident->{'type_instance'};
+  my $instance;
+
+  if (defined $type_instance)
+  {
+    $instance = $type_instance;
+  }
+  elsif (defined $plugin_instance)
+  {
+    $instance = $plugin_instance;
+  }
+  else
+  {
+    $instance = 'no instance';
+  }
 
   if (!defined $plugin_instance)
   {
@@ -264,6 +278,7 @@ sub getTitle
   $title =~ s#{plugin_instance}#$plugin_instance#g;
   $title =~ s#{type}#$type#g;
   $title =~ s#{type_instance}#$type_instance#g;
+  $title =~ s#{instance}#$instance#g;
 
   return ($title);
 }
@@ -334,10 +349,24 @@ sub getRRDArgs
     $f =~ s#:#\\:#g;
     $ds_name =~ s#:#\\:#g;
 
-    push (@ret,
-      "DEF:min${i}=${f}:${ds_name}:MIN",
-      "DEF:avg${i}=${f}:${ds_name}:AVERAGE",
-      "DEF:max${i}=${f}:${ds_name}:MAX");
+    if (exists ($obj->{'scale'}))
+    {
+      my $scale = 0.0 + $obj->{'scale'};
+      push (@ret,
+       "DEF:min${i}_raw=${f}:${ds_name}:MIN",
+       "DEF:avg${i}_raw=${f}:${ds_name}:AVERAGE",
+       "DEF:max${i}_raw=${f}:${ds_name}:MAX",
+       "CDEF:max${i}=max${i}_raw,$scale,*",
+       "CDEF:avg${i}=avg${i}_raw,$scale,*",
+       "CDEF:min${i}=min${i}_raw,$scale,*");
+    }
+    else
+    {
+      push (@ret,
+       "DEF:min${i}=${f}:${ds_name}:MIN",
+       "DEF:avg${i}=${f}:${ds_name}:AVERAGE",
+       "DEF:max${i}=${f}:${ds_name}:MAX");
+    }
   }
 
   if (@$ds == 1)