Skip to content

Commit b8cf3a1

Browse files
committed
in_node_exporter_metrics: add Linux sockstat collector
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 0d44379 commit b8cf3a1

File tree

6 files changed

+492
-1
lines changed

6 files changed

+492
-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_sockstat.c
1011
ne_time.c
1112
ne_loadavg.c
1213
ne_filefd.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_sockstat.h"
4243
#include "ne_textfile.h"
4344
#include "ne_systemd.h"
4445
#include "ne_processes.h"
@@ -192,6 +193,7 @@ static int in_ne_init(struct flb_input_instance *in,
192193
mk_list_add(&loadavg_collector._head, &ctx->collectors);
193194
mk_list_add(&vmstat_collector._head, &ctx->collectors);
194195
mk_list_add(&netdev_collector._head, &ctx->collectors);
196+
mk_list_add(&sockstat_collector._head, &ctx->collectors);
195197
mk_list_add(&filefd_collector._head, &ctx->collectors);
196198
mk_list_add(&textfile_collector._head, &ctx->collectors);
197199
mk_list_add(&systemd_collector._head, &ctx->collectors);
@@ -385,6 +387,12 @@ static struct flb_config_map config_map[] = {
385387
"scrape interval to collect netdev metrics from the node."
386388
},
387389

390+
{
391+
FLB_CONFIG_MAP_TIME, "collector.sockstat.scrape_interval", "0",
392+
0, FLB_FALSE, 0,
393+
"scrape interval to collect sockstat metrics from the node."
394+
},
395+
388396
{
389397
FLB_CONFIG_MAP_TIME, "collector.filefd.scrape_interval", "0",
390398
0, FLB_FALSE, 0,

plugins/in_node_exporter_metrics/ne.h

Lines changed: 23 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,filefd,systemd,nvme,thermal_zone"
36+
#define NE_DEFAULT_ENABLED_METRICS "cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,sockstat,filefd,systemd,nvme,thermal_zone"
3737
#elif __APPLE__
3838
#define NE_DEFAULT_ENABLED_METRICS "cpu,loadavg,meminfo,diskstats,uname,netdev"
3939
#endif
@@ -140,6 +140,28 @@ struct flb_ne {
140140
struct cmt_gauge *darwin_noproto;
141141
#endif
142142

143+
/* sockstat_linux */
144+
struct cmt_gauge *sockstat_sockets_used;
145+
struct cmt_gauge *sockstat_TCP_alloc;
146+
struct cmt_gauge *sockstat_TCP_inuse;
147+
struct cmt_gauge *sockstat_TCP_mem;
148+
struct cmt_gauge *sockstat_TCP_mem_bytes;
149+
struct cmt_gauge *sockstat_TCP_orphan;
150+
struct cmt_gauge *sockstat_TCP_tw;
151+
struct cmt_gauge *sockstat_UDP_inuse;
152+
struct cmt_gauge *sockstat_UDP_mem;
153+
struct cmt_gauge *sockstat_UDP_mem_bytes;
154+
struct cmt_gauge *sockstat_UDPLITE_inuse;
155+
struct cmt_gauge *sockstat_RAW_inuse;
156+
struct cmt_gauge *sockstat_FRAG_inuse;
157+
struct cmt_gauge *sockstat_FRAG_memory;
158+
struct cmt_gauge *sockstat_TCP6_inuse;
159+
struct cmt_gauge *sockstat_UDP6_inuse;
160+
struct cmt_gauge *sockstat_UDPLITE6_inuse;
161+
struct cmt_gauge *sockstat_RAW6_inuse;
162+
struct cmt_gauge *sockstat_FRAG6_inuse;
163+
struct cmt_gauge *sockstat_FRAG6_memory;
164+
143165
/* time */
144166
struct cmt_gauge *time;
145167

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_sockstat_linux.c"
22+
#else
23+
24+
#include "ne.h"
25+
26+
struct flb_ne_collector sockstat_collector = {
27+
.name = "sockstat",
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_SOCKSTAT_H
21+
#define FLB_IN_NE_SOCKSTAT_H
22+
23+
#include "ne.h"
24+
25+
extern struct flb_ne_collector sockstat_collector;
26+
27+
#endif

0 commit comments

Comments
 (0)