Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/in_node_exporter_metrics/ne.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ static int activate_collector(struct flb_ne *ctx, struct flb_config *config,

ret = coll->cb_init(ctx);
if (ret != 0) {
if (coll->cb_update && coll->coll_fd >= 0) {
flb_input_collector_delete(coll->coll_fd, ctx->ins);
coll->coll_fd = -1;
}
flb_plg_error(ctx->ins, "%s init failed", name);
return -1;
}
Expand Down Expand Up @@ -526,6 +530,12 @@ static struct flb_config_map config_map[] = {
"ignore regular expression for disk devices"
},

{
FLB_CONFIG_MAP_STR, "netdev.ignore_device_regex", NULL,
0, FLB_TRUE, offsetof(struct flb_ne, netdev_regex_skip_devices_text),
"ignore regular expression for network devices"
},

/* hwmon specific settings */
{
FLB_CONFIG_MAP_STR, "collector.hwmon.chip-include", NULL,
Expand Down
2 changes: 2 additions & 0 deletions plugins/in_node_exporter_metrics/ne.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ struct flb_ne {

/* netdev */
struct flb_hash_table *netdev_ht;
struct flb_regex *netdev_regex_skip_devices;
flb_sds_t netdev_regex_skip_devices_text;

#ifdef FLB_SYSTEM_MACOS
/* netdev_darwin */
Expand Down
38 changes: 35 additions & 3 deletions plugins/in_node_exporter_metrics/ne_netdev_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ static struct cmt_counter *netdev_hash_get(struct flb_ne *ctx,
return c;
}

static int netdev_skip_device(struct flb_ne *ctx, flb_sds_t device)
{
if (!ctx->netdev_regex_skip_devices) {
return FLB_FALSE;
}

return flb_regex_match(ctx->netdev_regex_skip_devices,
(unsigned char *) device,
flb_sds_len(device));
}

static int netdev_configure(struct flb_ne *ctx)
{
int ret;
Expand Down Expand Up @@ -291,9 +302,14 @@ static int netdev_update(struct flb_ne *ctx)
/* sanitize device name */
len = flb_sds_len(dev->str);
len--;
flb_sds_len_set(dev->str, len - 1);
flb_sds_len_set(dev->str, len);
dev->str[len] = '\0';

if (netdev_skip_device(ctx, dev->str)) {
flb_slist_destroy(&split_list);
continue;
}

/* iterate line fields */
n = 0;
mk_list_foreach(prop_head, &split_list) {
Expand Down Expand Up @@ -344,8 +360,19 @@ static int netdev_update(struct flb_ne *ctx)

static int ne_netdev_init(struct flb_ne *ctx)
{
netdev_configure(ctx);
return 0;
if (ctx->netdev_regex_skip_devices_text) {
ctx->netdev_regex_skip_devices =
flb_regex_create(ctx->netdev_regex_skip_devices_text);
if (!ctx->netdev_regex_skip_devices) {
flb_plg_error(ctx->ins,
"could not initialize regex pattern for ignored "
"network devices: '%s'",
ctx->netdev_regex_skip_devices_text);
return -1;
Comment thread
cosmo0920 marked this conversation as resolved.
}
}

return netdev_configure(ctx);
}

static int ne_netdev_update(struct flb_input_instance *ins, struct flb_config *config, void *in_context)
Expand All @@ -361,6 +388,11 @@ static int ne_netdev_exit(struct flb_ne *ctx)
if (ctx->netdev_ht) {
flb_hash_table_destroy(ctx->netdev_ht);
}

if (ctx->netdev_regex_skip_devices) {
flb_regex_destroy(ctx->netdev_regex_skip_devices);
}

return 0;
}

Expand Down