Skip to content

Commit 243d431

Browse files
committed
in_node_exporter_metrics: add netstat linux collector
Extend node_exporter_metrics by exposing netstat metrics by parsing /proc/net/snmp data and aligning the output with Prometheus node_exporter conventions. Example parsed values from a live system: node_netstat_Tcp_ActiveOpens = 26581 node_netstat_Tcp_PassiveOpens = 129 node_netstat_Tcp_RetransSegs = 9254 node_netstat_Tcp_CurrEstab = 6 node_netstat_Udp_InDatagrams = 1292553 node_netstat_Udp_OutDatagrams = 1601161 node_netstat_Udp_NoPorts = 2047 node_netstat_Udp_InErrors = 0 Signed-off-by: Eduardo Silva <[email protected]>
1 parent d87ec0d commit 243d431

File tree

6 files changed

+362
-1
lines changed

6 files changed

+362
-1
lines changed

plugins/in_node_exporter_metrics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(src
77
ne_stat.c
88
ne_vmstat.c
99
ne_netdev.c
10+
ne_netstat.c
1011
ne_sockstat.c
1112
ne_time.c
1213
ne_loadavg.c

plugins/in_node_exporter_metrics/ne.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "ne_loadavg.h"
4040
#include "ne_vmstat.h"
4141
#include "ne_netdev.h"
42+
#include "ne_netstat.h"
4243
#include "ne_sockstat.h"
4344
#include "ne_textfile.h"
4445
#include "ne_systemd.h"
@@ -194,6 +195,7 @@ static int in_ne_init(struct flb_input_instance *in,
194195
mk_list_add(&loadavg_collector._head, &ctx->collectors);
195196
mk_list_add(&vmstat_collector._head, &ctx->collectors);
196197
mk_list_add(&netdev_collector._head, &ctx->collectors);
198+
mk_list_add(&netstat_collector._head, &ctx->collectors);
197199
mk_list_add(&sockstat_collector._head, &ctx->collectors);
198200
mk_list_add(&filefd_collector._head, &ctx->collectors);
199201
mk_list_add(&textfile_collector._head, &ctx->collectors);
@@ -389,6 +391,12 @@ static struct flb_config_map config_map[] = {
389391
"scrape interval to collect netdev metrics from the node."
390392
},
391393

394+
{
395+
FLB_CONFIG_MAP_TIME, "collector.netstat.scrape_interval", "0",
396+
0, FLB_FALSE, 0,
397+
"scrape interval to collect netstat metrics from the node."
398+
},
399+
392400
{
393401
FLB_CONFIG_MAP_TIME, "collector.sockstat.scrape_interval", "0",
394402
0, FLB_FALSE, 0,

plugins/in_node_exporter_metrics/ne.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/* Default enabled metrics */
3434

3535
#ifdef __linux__
36-
#define NE_DEFAULT_ENABLED_METRICS "cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,sockstat,filefd,systemd,nvme,thermal_zone,hwmon"
36+
#define NE_DEFAULT_ENABLED_METRICS "cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,netstat,sockstat,filefd,systemd,nvme,thermal_zone,hwmon"
3737
#elif __APPLE__
3838
#define NE_DEFAULT_ENABLED_METRICS "cpu,loadavg,meminfo,diskstats,uname,netdev"
3939
#endif
@@ -163,6 +163,16 @@ struct flb_ne {
163163
struct cmt_gauge *sockstat_FRAG6_inuse;
164164
struct cmt_gauge *sockstat_FRAG6_memory;
165165

166+
/* netstat_linux */
167+
struct cmt_gauge *netstat_Tcp_CurrEstab;
168+
struct cmt_counter *netstat_Tcp_ActiveOpens;
169+
struct cmt_counter *netstat_Tcp_PassiveOpens;
170+
struct cmt_counter *netstat_Tcp_RetransSegs;
171+
struct cmt_counter *netstat_Udp_InDatagrams;
172+
struct cmt_counter *netstat_Udp_InErrors;
173+
struct cmt_counter *netstat_Udp_OutDatagrams;
174+
struct cmt_counter *netstat_Udp_NoPorts;
175+
166176
/* time */
167177
struct cmt_gauge *time;
168178

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2025 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifdef __linux__
21+
#include "ne_netstat_linux.c"
22+
#else
23+
24+
#include "ne.h"
25+
26+
struct flb_ne_collector netstat_collector = {
27+
.name = "netstat",
28+
.cb_init = NULL,
29+
.cb_update = NULL,
30+
.cb_exit = NULL
31+
};
32+
33+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2025 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef FLB_IN_NE_NETSTAT_H
21+
#define FLB_IN_NE_NETSTAT_H
22+
23+
#include "ne.h"
24+
25+
extern struct flb_ne_collector netstat_collector;
26+
27+
#endif

0 commit comments

Comments
 (0)