Merge branch 'collectd-4.10' into collectd-5.0
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Mon, 7 Feb 2011 07:47:35 +0000 (08:47 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Mon, 7 Feb 2011 07:47:35 +0000 (08:47 +0100)
src/exec.c
src/ntpd.c
src/threshold.c

index 8d5ae9c..0d33b29 100644 (file)
@@ -283,10 +283,6 @@ static void set_environment (void) /* {{{ */
   ssnprintf (buffer, sizeof (buffer), "COLLECTD_HOSTNAME=%s", hostname_g);
   putenv (buffer);
 #endif
-
-#ifdef HAVE_SETENV
-#else
-#endif
 } /* }}} void set_environment */
 
 __attribute__((noreturn))
index ecc87c7..8bbf74d 100644 (file)
@@ -784,15 +784,15 @@ static int ntpd_read (void)
                        0, 0, NULL, /* request data */
                        &ik_num, &ik_size, (char **) ((void *) &ik), /* response data */
                        sizeof (struct info_kernel));
-
        if (status != 0)
        {
-               DEBUG ("ntpd_do_query failed with status %i", status);
-               return (-1);
+               ERROR ("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i", status);
+               return (status);
        }
-       if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
+       else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
        {
-               DEBUG ("ntpd_do_query returned: ik = %p; ik_num = %i; ik_size = %i;",
+               ERROR ("ntpd plugin: ntpd_do_query returned unexpected data. "
+                               "(ik = %p; ik_num = %i; ik_size = %i)",
                                (void *) ik, ik_num, ik_size);
                return (-1);
        }
@@ -820,12 +820,13 @@ static int ntpd_read (void)
                        sizeof (struct info_peer_summary));
        if (status != 0)
        {
-               DEBUG ("ntpd_do_query failed with status %i", status);
-               return (-1);
+               ERROR ("ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i", status);
+               return (status);
        }
-       if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
+       else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
        {
-               DEBUG ("ntpd_do_query returned: ps = %p; ps_num = %i; ps_size = %i;",
+               ERROR ("ntpd plugin: ntpd_do_query returned unexpected data. "
+                               "(ps = %p; ps_num = %i; ps_size = %i)",
                                (void *) ps, ps_num, ps_size);
                return (-1);
        }
index 369051a..277b453 100644 (file)
@@ -717,15 +717,41 @@ static int ut_report_state (const data_set_t *ds,
            ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
       }
     }
+    else if (th->flags & UT_FLAG_PERCENTAGE)
+    {
+      gauge_t value;
+      gauge_t sum;
+      int i;
+
+      sum = 0.0;
+      for (i = 0; i < vl->values_len; i++)
+      {
+        if (isnan (values[i]))
+          continue;
+
+        sum += values[i];
+      }
+
+      if (sum == 0.0)
+        value = NAN;
+      else
+        value = 100.0 * values[ds_index] / sum;
+
+      status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+          "%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
+          ds->ds[ds_index].name, values[ds_index], value,
+          (value < min) ? "below" : "above",
+          (state == STATE_ERROR) ? "failure" : "warning",
+          (value < min) ? min : max);
+    }
     else /* is not inverted */
     {
       status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
-         "%f. That is %s the %s threshold of %f%s.",
+         "%f. That is %s the %s threshold of %f.",
          ds->ds[ds_index].name, values[ds_index],
          (values[ds_index] < min) ? "below" : "above",
          (state == STATE_ERROR) ? "failure" : "warning",
-         (values[ds_index] < min) ? min : max,
-         ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
+         (values[ds_index] < min) ? min : max);
     }
     buf += status;
     bufsize -= status;