Merge pull request #2512 from Stackdriver/pri
[collectd.git] / src / processes.c
index 2e9715d..d73d24a 100644 (file)
@@ -657,7 +657,7 @@ static void ps_tune_instance(oconfig_item_t *ci, procstat_t *ps) {
               "for the \"CollectDelayAccounting\" option.");
 #endif
     } else {
               "for the \"CollectDelayAccounting\" option.");
 #endif
     } else {
-      ERROR("processes plugin: Option `%s' not allowed heeere.", c->key);
+      ERROR("processes plugin: Option \"%s\" not allowed here.", c->key);
     }
   } /* for (ci->children) */
 } /* void ps_tune_instance */
     }
   } /* for (ci->children) */
 } /* void ps_tune_instance */
@@ -685,7 +685,8 @@ static int ps_config(oconfig_item_t *ci) {
 
 #if KERNEL_LINUX || KERNEL_SOLARIS || KERNEL_FREEBSD
       if (strlen(c->values[0].value.string) > max_procname_len) {
 
 #if KERNEL_LINUX || KERNEL_SOLARIS || KERNEL_FREEBSD
       if (strlen(c->values[0].value.string) > max_procname_len) {
-        WARNING("processes plugin: this platform has a %zu character limit "
+        WARNING("processes plugin: this platform has a %" PRIsz
+                " character limit "
                 "to process names. The `Process \"%s\"' option will "
                 "not work as expected.",
                 max_procname_len, c->values[0].value.string);
                 "to process names. The `Process \"%s\"' option will "
                 "not work as expected.",
                 max_procname_len, c->values[0].value.string);
@@ -903,38 +904,27 @@ static void ps_submit_proc_list(procstat_t *ps) {
     plugin_dispatch_values(&vl);
   }
 
     plugin_dispatch_values(&vl);
   }
 
-  /* The ps->delay_* metrics are in nanoseconds per second. This factor converts
-   * them to a percentage. */
-  gauge_t const delay_factor = 100.0 / 1000000000.0;
-
-  if (!isnan(ps->delay_cpu)) {
-    sstrncpy(vl.type, "percent", sizeof(vl.type));
-    sstrncpy(vl.type_instance, "delay-cpu", sizeof(vl.type_instance));
-    vl.values[0].gauge = ps->delay_cpu * delay_factor;
-    vl.values_len = 1;
-    plugin_dispatch_values(&vl);
-  }
-
-  if (!isnan(ps->delay_blkio)) {
-    sstrncpy(vl.type, "percent", sizeof(vl.type));
-    sstrncpy(vl.type_instance, "delay-blkio", sizeof(vl.type_instance));
-    vl.values[0].gauge = ps->delay_blkio * delay_factor;
-    vl.values_len = 1;
-    plugin_dispatch_values(&vl);
-  }
-
-  if (!isnan(ps->delay_swapin)) {
-    sstrncpy(vl.type, "percent", sizeof(vl.type));
-    sstrncpy(vl.type_instance, "delay-swapin", sizeof(vl.type_instance));
-    vl.values[0].gauge = ps->delay_swapin * delay_factor;
-    vl.values_len = 1;
-    plugin_dispatch_values(&vl);
-  }
-
-  if (!isnan(ps->delay_freepages)) {
-    sstrncpy(vl.type, "percent", sizeof(vl.type));
-    sstrncpy(vl.type_instance, "delay-freepages", sizeof(vl.type_instance));
-    vl.values[0].gauge = ps->delay_freepages * delay_factor;
+  /* The ps->delay_* metrics are in nanoseconds per second. Convert to seconds
+   * per second. */
+  gauge_t const delay_factor = 1000000000.0;
+
+  struct {
+    char *type_instance;
+    gauge_t rate_ns;
+  } delay_metrics[] = {
+      {"delay-cpu", ps->delay_cpu},
+      {"delay-blkio", ps->delay_blkio},
+      {"delay-swapin", ps->delay_swapin},
+      {"delay-freepages", ps->delay_freepages},
+  };
+  for (size_t i = 0; i < STATIC_ARRAY_SIZE(delay_metrics); i++) {
+    if (isnan(delay_metrics[i].rate_ns)) {
+      continue;
+    }
+    sstrncpy(vl.type, "delay_rate", sizeof(vl.type));
+    sstrncpy(vl.type_instance, delay_metrics[i].type_instance,
+             sizeof(vl.type_instance));
+    vl.values[0].gauge = delay_metrics[i].rate_ns * delay_factor;
     vl.values_len = 1;
     plugin_dispatch_values(&vl);
   }
     vl.values_len = 1;
     plugin_dispatch_values(&vl);
   }
@@ -1259,10 +1249,6 @@ static int ps_delay(process_entry_t *ps) {
 
   return 0;
 }
 
   return 0;
 }
-#else
-static int ps_delay(__attribute__((unused)) process_entry_t *unused) {
-  return -1;
-}
 #endif
 
 static void ps_fill_details(const procstat_t *ps, process_entry_t *entry) {
 #endif
 
 static void ps_fill_details(const procstat_t *ps, process_entry_t *entry) {
@@ -1350,7 +1336,8 @@ static int ps_read_process(long pid, process_entry_t *ps, char *state) {
   /* Either '(' or ')' is not found or they are in the wrong order.
    * Anyway, something weird that shouldn't happen ever. */
   if (name_start_pos >= name_end_pos) {
   /* Either '(' or ')' is not found or they are in the wrong order.
    * Anyway, something weird that shouldn't happen ever. */
   if (name_start_pos >= name_end_pos) {
-    ERROR("processes plugin: name_start_pos = %zu >= name_end_pos = %zu",
+    ERROR("processes plugin: name_start_pos = %" PRIsz
+          " >= name_end_pos = %" PRIsz,
           name_start_pos, name_end_pos);
     return -1;
   }
           name_start_pos, name_end_pos);
     return -1;
   }
@@ -1584,7 +1571,7 @@ static char *ps_get_cmdline(long pid,
   if ((status < 0) || (((size_t)status) != sizeof(info))) {
     ERROR("processes plugin: Unexpected return value "
           "while reading \"%s\": "
   if ((status < 0) || (((size_t)status) != sizeof(info))) {
     ERROR("processes plugin: Unexpected return value "
           "while reading \"%s\": "
-          "Returned %zd but expected %zu.",
+          "Returned %zd but expected %" PRIsz ".",
           path, status, buffer_size);
     return NULL;
   }
           path, status, buffer_size);
     return NULL;
   }