Merge pull request #681 from pyr/feature/use-collectd-hostname
authorPierre-Yves Ritschard <pyr@spootnik.org>
Tue, 29 Jul 2014 14:20:09 +0000 (16:20 +0200)
committerPierre-Yves Ritschard <pyr@spootnik.org>
Tue, 29 Jul 2014 14:20:09 +0000 (16:20 +0200)
Bring in hostname as defined in the main configuration by default

src/utils_latency.c

index 94da211..7699f57 100644 (file)
@@ -128,7 +128,7 @@ cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */
 {
   double average;
 
-  if (lc == NULL)
+  if ((lc == NULL) || (lc->num == 0))
     return (0);
 
   average = CDTIME_T_TO_DOUBLE (lc->sum) / ((double) lc->num);
@@ -146,7 +146,7 @@ cdtime_t latency_counter_get_percentile (latency_counter_t *lc,
   int sum;
   size_t i;
 
-  if ((lc == NULL) || !((percent > 0.0) && (percent < 100.0)))
+  if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0)))
     return (0);
 
   /* Find index i so that at least "percent" events are within i+1 ms. */