write_prometheus: add support for libmicrohttpd 0.9.45+
[collectd.git] / src / dpdkstat.c
index 5842543..7d89596 100644 (file)
@@ -147,13 +147,13 @@ static void dpdk_config_init_default(void) {
 
 static int dpdk_config(oconfig_item_t *ci) {
   int port_counter = 0;
-  char errbuf[ERR_BUF_SIZE];
   /* Allocate g_configuration and
    * initialize a POSIX SHared Memory (SHM) object.
    */
   int err = dpdk_shm_init(sizeof(dpdk_config_t));
   if (err) {
-    DEBUG("dpdkstat: error in shm_init, %s",
+    char errbuf[ERR_BUF_SIZE];
+    ERROR("dpdkstat: error in shm_init, %s",
           sstrerror(errno, errbuf, sizeof(errbuf)));
     return -1;
   }
@@ -447,12 +447,12 @@ static int dpdk_helper_run(void) {
 
   while (1) {
     /* sem_timedwait() to avoid blocking forever */
-    struct timespec ts;
     cdtime_t now = cdtime();
     cdtime_t safety_period = MS_TO_CDTIME_T(1500);
-    CDTIME_T_TO_TIMESPEC(now + safety_period + g_configuration->interval * 2,
-                         &ts);
-    int ret = sem_timedwait(&g_configuration->sema_helper_get_stats, &ts);
+    int ret =
+        sem_timedwait(&g_configuration->sema_helper_get_stats,
+                      &CDTIME_T_TO_TIMESPEC(now + safety_period +
+                                            g_configuration->interval * 2));
 
     if (ret == -1 && errno == ETIMEDOUT) {
       ERROR("dpdkstat-helper: sem timedwait()"
@@ -555,76 +555,73 @@ static void dpdk_submit_xstats(const char *dev_name,
                                const struct rte_eth_xstats *xstats,
                                uint32_t counters, cdtime_t port_read_time) {
   for (uint32_t j = 0; j < counters; j++) {
-    value_list_t dpdkstat_vl = VALUE_LIST_INIT;
+    value_list_t vl = VALUE_LIST_INIT;
     char *type_end;
 
-    dpdkstat_vl.values = &(value_t){.derive = (derive_t)xstats[j].value};
-    dpdkstat_vl.values_len = 1; /* Submit stats one at a time */
-    dpdkstat_vl.time = port_read_time;
-    sstrncpy(dpdkstat_vl.host, hostname_g, sizeof(dpdkstat_vl.host));
-    sstrncpy(dpdkstat_vl.plugin, "dpdkstat", sizeof(dpdkstat_vl.plugin));
-    sstrncpy(dpdkstat_vl.plugin_instance, dev_name,
-             sizeof(dpdkstat_vl.plugin_instance));
+    vl.values = &(value_t){.derive = (derive_t)xstats[j].value};
+    vl.values_len = 1; /* Submit stats one at a time */
+    vl.time = port_read_time;
+    sstrncpy(vl.plugin, "dpdkstat", sizeof(vl.plugin));
+    sstrncpy(vl.plugin_instance, dev_name, sizeof(vl.plugin_instance));
 
     type_end = strrchr(xstats[j].name, '_');
 
     if ((type_end != NULL) &&
         (strncmp(xstats[j].name, "rx_", strlen("rx_")) == 0)) {
       if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_rx_errors", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_rx_errors", sizeof(vl.type));
       } else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_rx_dropped", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_rx_dropped", sizeof(vl.type));
       } else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_rx_octets", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_rx_octets", sizeof(vl.type));
       } else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_rx_packets", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_rx_packets", sizeof(vl.type));
       } else if (strncmp(type_end, "_placement", strlen("_placement")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_rx_errors", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_rx_errors", sizeof(vl.type));
       } else if (strncmp(type_end, "_buff", strlen("_buff")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_rx_errors", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_rx_errors", sizeof(vl.type));
       } else {
         /* Does not fit obvious type: use a more generic one */
-        sstrncpy(dpdkstat_vl.type, "derive", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "derive", sizeof(vl.type));
       }
 
     } else if ((type_end != NULL) &&
                (strncmp(xstats[j].name, "tx_", strlen("tx_"))) == 0) {
       if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_tx_errors", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_tx_errors", sizeof(vl.type));
       } else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_tx_dropped", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_tx_dropped", sizeof(vl.type));
       } else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_tx_octets", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_tx_octets", sizeof(vl.type));
       } else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "if_tx_packets", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "if_tx_packets", sizeof(vl.type));
       } else {
         /* Does not fit obvious type: use a more generic one */
-        sstrncpy(dpdkstat_vl.type, "derive", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "derive", sizeof(vl.type));
       }
     } else if ((type_end != NULL) &&
                (strncmp(xstats[j].name, "flow_", strlen("flow_"))) == 0) {
 
       if (strncmp(type_end, "_filters", strlen("_filters")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "operations", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "operations", sizeof(vl.type));
       } else if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "errors", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "errors", sizeof(vl.type));
       } else if (strncmp(type_end, "_filters", strlen("_filters")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "filter_result", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "filter_result", sizeof(vl.type));
       }
     } else if ((type_end != NULL) &&
                (strncmp(xstats[j].name, "mac_", strlen("mac_"))) == 0) {
       if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
-        sstrncpy(dpdkstat_vl.type, "errors", sizeof(dpdkstat_vl.type));
+        sstrncpy(vl.type, "errors", sizeof(vl.type));
       }
     } else {
       /* Does not fit obvious type, or strrchr error:
        *   use a more generic type */
-      sstrncpy(dpdkstat_vl.type, "derive", sizeof(dpdkstat_vl.type));
+      sstrncpy(vl.type, "derive", sizeof(vl.type));
     }
 
-    sstrncpy(dpdkstat_vl.type_instance, xstats[j].name,
-             sizeof(dpdkstat_vl.type_instance));
-    plugin_dispatch_values(&dpdkstat_vl);
+    sstrncpy(vl.type_instance, xstats[j].name, sizeof(vl.type_instance));
+    plugin_dispatch_values(&vl);
   }
 }
 
@@ -701,10 +698,9 @@ static int dpdk_read(user_data_t *ud) {
   /* Kick helper process through SHM */
   sem_post(&g_configuration->sema_helper_get_stats);
 
-  struct timespec ts;
   cdtime_t now = cdtime();
-  CDTIME_T_TO_TIMESPEC(now + g_configuration->interval, &ts);
-  ret = sem_timedwait(&g_configuration->sema_stats_in_shm, &ts);
+  ret = sem_timedwait(&g_configuration->sema_stats_in_shm,
+                      &CDTIME_T_TO_TIMESPEC(now + g_configuration->interval));
   if (ret == -1) {
     if (errno == ETIMEDOUT)
       DEBUG(