]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Integrate distribution metrics into collectd core: add new distribution_t value to...
authorelene-margalit <elene.margalit@gmail.com>
Sun, 16 Aug 2020 17:18:28 +0000 (19:18 +0200)
committerelene-margalit <elene.margalit@gmail.com>
Sun, 16 Aug 2020 17:18:28 +0000 (19:18 +0200)
src/daemon/metric.c
src/daemon/metric.h

index 16052be6117762e2a703c9284acb71ddf281c817..2196b36ff0f7131e776e33177a8a4ff93f4d1967 100644 (file)
@@ -26,7 +26,6 @@
  **/
 
 #include "collectd.h"
-
 #include "metric.h"
 #include "plugin.h"
 
@@ -206,6 +205,10 @@ int metric_reset(metric_t *m) {
   label_set_reset(&m->label);
   meta_data_destroy(m->meta);
 
+  if(m->family->type == METRIC_TYPE_DISTRIBUTION) {
+    distribution_destroy(m->value.distribution);
+  }
+
   memset(m, 0, sizeof(*m));
 
   return 0;
@@ -345,12 +348,19 @@ static int metric_list_clone(metric_list_t *dest, metric_list_t src,
   }
 
   for (size_t i = 0; i < src.num; i++) {
-    ret.ptr[i] = (metric_t){
+
+      ret.ptr[i] = (metric_t){
         .family = fam,
-        .value = src.ptr[i].value,
         .time = src.ptr[i].time,
         .interval = src.ptr[i].interval,
-    };
+      };
+
+      if(src.ptr[i].family->type == METRIC_TYPE_DISTRIBUTION) {
+          ret.ptr[i].value.distribution = distribution_clone(src.ptr[i].value.distribution);    
+      }
+      else {
+          ret.ptr[i].value = src.ptr[i].value;
+      }
 
     int status = label_set_clone(&ret.ptr[i].label, src.ptr[i].label);
     if (status != 0) {
@@ -623,3 +633,4 @@ metric_t *metric_parse_identity(char const *buf) {
 
   return fam->metric.ptr;
 }
+
index 0419304ede8e227e80b9a11874b7629a82ba2694..6af52562f995db2c9d863b04da413d03ecbd2852 100644 (file)
@@ -31,6 +31,7 @@
 #include "utils/metadata/meta_data.h"
 #include "utils/strbuf/strbuf.h"
 #include "utils_time.h"
+#include "distribution.h"
 
 #define VALUE_TYPE_GAUGE 1
 #define VALUE_TYPE_DERIVE 2
@@ -39,6 +40,7 @@ typedef enum {
   METRIC_TYPE_COUNTER = 0,
   METRIC_TYPE_GAUGE = 1,
   METRIC_TYPE_UNTYPED = 2,
+  METRIC_TYPE_DISTRIBUTION = 3,
 } metric_type_t;
 
 typedef uint64_t counter_t;
@@ -49,6 +51,7 @@ union value_u {
   counter_t counter;
   gauge_t gauge;
   derive_t derive;
+  distribution_t *distribution;
 };
 typedef union value_u value_t;
 
@@ -125,7 +128,7 @@ int metric_label_set(metric_t *m, char const *name, char const *value);
 char const *metric_label_get(metric_t const *m, char const *name);
 
 /* metric_reset frees all labels and meta data stored in the metric and resets
- * the metric to zero. */
+ * the metric to zero. If the metric is a distribution metric, the function frees the according distribution.*/
 int metric_reset(metric_t *m);
 
 /* metric_list_t is an unordered list of metrics. */
@@ -175,4 +178,10 @@ void metric_family_free(metric_family_t *fam);
  * metric_family_free(). */
 metric_family_t *metric_family_clone(metric_family_t const *fam);
 
+/*The static function metric_list_clone creates a clone of the argument metric_list_t src. For each metric_t element
+ *in the src list it checks if its value is a distribution metric and if yes, calls the distribution_clone function
+ *for the value and saves the pointer to the returned distribution_t clone into the metric_list_t dest. If
+ *the value is not a distribution_t, it simply sets the value of the element in the destination list to the value
+ *of the element in the source list. */ 
+
 #endif