Code

write_tsdb plugin: Add type and type_instance to the metric name in any case.
authorDallin Young <dallin.young@gmail.com>
Fri, 20 Feb 2015 18:33:00 +0000 (19:33 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 10 Mar 2015 14:18:50 +0000 (15:18 +0100)
Previously, the generated names were wrong, especially when no
plugin instance was used for a metric.

Fixes: #945
Signed-off-by: Florian Forster <octo@collectd.org>
src/write_tsdb.c

index b7f46f1b9abde92bae63eee39d244e7fa6380ae2..bfac1a140d4020c065f7b473e5a19dc72013ad90 100644 (file)
@@ -365,24 +365,32 @@ static int wt_format_name(char *ret, int ret_len,
 
     if (ds_name != NULL) {
         if (vl->plugin_instance[0] == '\0') {
-            ssnprintf(ret, ret_len, "%s%s.%s",
-                      prefix, vl->plugin, ds_name);
+            if (vl->type_instance[0] == '\0') {
+                ssnprintf(ret, ret_len, "%s%s.%s.%s",
+                          prefix, vl->plugin, vl->type,
+                          ds_name);
+            } else {
+                ssnprintf(ret, ret_len, "%s%s.%s.%s",
+                          prefix, vl->plugin, vl->type_instance,
+                          ds_name);
+            }
         } else if (vl->type_instance[0] == '\0') {
-            ssnprintf(ret, ret_len, "%s%s.%s.%s.%s",
-                      prefix, vl->plugin, vl->plugin_instance,
-                      vl->type_instance, ds_name);
-        } else {
             ssnprintf(ret, ret_len, "%s%s.%s.%s.%s",
                       prefix, vl->plugin, vl->plugin_instance, vl->type,
                       ds_name);
+        } else {
+            ssnprintf(ret, ret_len, "%s%s.%s.%s.%s.%s",
+                      prefix, vl->plugin, vl->plugin_instance, vl->type,
+                      vl->type_instance, ds_name);
         }
     } else if (vl->plugin_instance[0] == '\0') {
-        if (vl->type_instance[0] == '\0')
+        if (vl->type_instance[0] == '\0') {
             ssnprintf(ret, ret_len, "%s%s.%s",
                       prefix, vl->plugin, vl->type);
-        else
+        } else {
             ssnprintf(ret, ret_len, "%s%s.%s",
                       prefix, vl->plugin, vl->type_instance);
+        }
     } else if (vl->type_instance[0] == '\0') {
         ssnprintf(ret, ret_len, "%s%s.%s.%s",
                   prefix, vl->plugin, vl->plugin_instance, vl->type);