aboutsummaryrefslogtreecommitdiffstats
path: root/telemetry/vpp-collectd/vpp/vpp.c
diff options
context:
space:
mode:
Diffstat (limited to 'telemetry/vpp-collectd/vpp/vpp.c')
-rw-r--r--telemetry/vpp-collectd/vpp/vpp.c128
1 files changed, 57 insertions, 71 deletions
diff --git a/telemetry/vpp-collectd/vpp/vpp.c b/telemetry/vpp-collectd/vpp/vpp.c
index 679f8feb4..ff70f3503 100644
--- a/telemetry/vpp-collectd/vpp/vpp.c
+++ b/telemetry/vpp-collectd/vpp/vpp.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -13,26 +13,9 @@
* limitations under the License.
*/
-#if !HAVE_CONFIG_H
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef __USE_ISOC99 /* required for NAN */
-#define DISABLE_ISOC99 1
-#define __USE_ISOC99 1
-#endif /* !defined(__USE_ISOC99) */
-
-#if DISABLE_ISOC99
-#undef DISABLE_ISOC99
-#undef __USE_ISOC99
-#endif /* DISABLE_ISOC99 */
-#endif /* ! HAVE_CONFIG */
-
-/* Keep order as it is */
-#include <config.h>
-#include <collectd.h>
-#include <common.h>
-#include <plugin.h>
+#include "collectd.h"
+#include "plugin.h"
+#include "utils/common/common.h"
#define counter_t vpp_counter_t
#include <vpp-api/client/stat_client.h>
@@ -164,7 +147,6 @@ static data_set_t if_tx_broadcast_ds = {
/**********************************************************/
/********** UTILITY FUNCTIONS *****************************/
/**********************************************************/
-
/*
* Utility function used by the read callback to populate a
* value_list_t and pass it to plugin_dispatch_values.
@@ -183,8 +165,7 @@ static int submit(const char *plugin_instance, const char *type,
sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
sstrncpy(vl.type, type, sizeof(vl.type));
- if (tag != NULL)
- sstrncpy(vl.type_instance, tag, sizeof(vl.type_instance));
+ if (tag != NULL) sstrncpy(vl.type_instance, tag, sizeof(vl.type_instance));
return plugin_dispatch_values(&vl);
}
@@ -247,7 +228,6 @@ static int get_data_set(const char *stat_name, data_set_t *data_set_ptr) {
/**********************************************************/
/********** CALLBACK FUNCTIONS ****************************/
/**********************************************************/
-
/*
* This function is called for each configuration item.
*/
@@ -274,11 +254,13 @@ static int vpp_config(const char *key, const char *value) {
* This function is called once upon startup to initialize the plugin.
*/
static int vpp_init(void) {
+ /* Create a heap of 64MB */
+ clib_mem_init(0, 64ULL << 20);
+
u8 *stat_segment_name = (u8 *)STAT_SEGMENT_SOCKET_FILE;
int ret = stat_segment_connect((char *)stat_segment_name);
- if (ret)
- plugin_log(LOG_ERR, "vpp plugin: connecting to segment failed");
+ if (ret) plugin_log(LOG_ERR, "vpp plugin: connecting to segment failed");
return ret;
}
@@ -291,7 +273,6 @@ static int vpp_read(void) {
char **interfaces = {0};
vec_add1(patterns, (uint8_t *)"^/if");
- vec_add1(patterns, (uint8_t *)"ip4-input");
uint32_t *dir = stat_segment_ls(patterns);
stat_segment_data_t *res = stat_segment_dump(dir);
@@ -300,9 +281,7 @@ static int vpp_read(void) {
for (int k = 0; k < vec_len(res); k++) {
if (res[k].type == STAT_DIR_TYPE_NAME_VECTOR) {
for (int i = 0; i < vec_len(res[k].name_vector); i++) {
- if (res[k].name_vector[i]) {
- vec_add1(interfaces, (char *)res[k].name_vector[i]);
- }
+ vec_add1(interfaces, (char *)res[k].name_vector[i]);
}
break;
}
@@ -315,58 +294,65 @@ static int vpp_read(void) {
/* Collect results for each interface and submit them */
for (int i = 0; i < vec_len(res); i++) {
switch (res[i].type) {
- case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
- for (int k = 0; k < vec_len(res[i].simple_counter_vec); k++) {
- for (int j = 0; j < vec_len(res[i].simple_counter_vec[k]); j++) {
- value_t values[1] = {
- (value_t){.derive = res[i].simple_counter_vec[k][j]}};
-
- if (get_data_set(res[i].name, &data_set)) {
- continue;
- }
+ case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
+ for (int k = 0; k < vec_len(res[i].simple_counter_vec); k++) {
+ for (int j = 0; j < vec_len(res[i].simple_counter_vec[k]); j++) {
+ if (!interfaces[j]) {
+ continue;
+ }
- err = submit(interfaces[j], data_set.type, values, 1, &timestamp);
+ if (get_data_set(res[i].name, &data_set)) {
+ continue;
+ }
- if (err)
- goto END;
- }
- }
- break;
+ value_t values[1] = {
+ (value_t){.derive = res[i].simple_counter_vec[k][j]}};
- case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
- for (int k = 0; k < vec_len(res[i].combined_counter_vec); k++) {
- for (int j = 0; j < vec_len(res[i].combined_counter_vec[k]); j++) {
- value_t values[2] = {
- (value_t){.derive = res[i].combined_counter_vec[k][j].packets},
- (value_t){.derive = res[i].combined_counter_vec[k][j].bytes},
- };
+ err = submit(interfaces[j], data_set.type, values, 1, &timestamp);
- if (get_data_set(res[i].name, &data_set)) {
- continue;
+ if (err) goto END;
}
+ }
+ break;
+
+ case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
+ for (int k = 0; k < vec_len(res[i].combined_counter_vec); k++) {
+ for (int j = 0; j < vec_len(res[i].combined_counter_vec[k]); j++) {
+ if (!interfaces[j]) {
+ continue;
+ }
+
+ if (get_data_set(res[i].name, &data_set)) {
+ continue;
+ }
- err = submit(interfaces[j], data_set.type, values, 2, &timestamp);
+ value_t values[2] = {
+ (value_t){.derive = res[i].combined_counter_vec[k][j].packets},
+ (value_t){.derive = res[i].combined_counter_vec[k][j].bytes},
+ };
- if (err)
- goto END;
+ err = submit(interfaces[j], data_set.type, values, 2, &timestamp);
+
+ if (err) goto END;
+ }
}
- }
- break;
+ break;
- case STAT_DIR_TYPE_SCALAR_INDEX:
- plugin_log(LOG_INFO, "vpp plugin: %.2f %s", res[i].scalar_value,
- res[i].name);
- break;
+ case STAT_DIR_TYPE_SCALAR_INDEX:
+ plugin_log(LOG_INFO, "vpp plugin: %.2f %s", res[i].scalar_value,
+ res[i].name);
+ break;
- case STAT_DIR_TYPE_NAME_VECTOR:
- break;
+ case STAT_DIR_TYPE_NAME_VECTOR:
+ break;
- case STAT_DIR_TYPE_ERROR_INDEX:
- break;
+ case STAT_DIR_TYPE_ERROR_INDEX:
+ break;
- default:
- plugin_log(LOG_WARNING, "vpp plugin: unknown stat type %d", res[i].type);
- break;
+ default:
+ plugin_log(LOG_WARNING, "vpp plugin: unknown stat type %d",
+ res[i].type);
+ break;
}
}