Skip to content

Commit 7ee9cc4

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

File tree

7 files changed

+485
-1
lines changed

7 files changed

+485
-1
lines changed

plugins/in_node_exporter_metrics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(src
1414
ne_textfile.c
1515
ne_processes.c
1616
ne_nvme.c
17+
ne_hwmon.c
1718
ne_utils.c
1819
ne_config.c
1920
ne_systemd.c

plugins/in_node_exporter_metrics/ne.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "ne_processes.h"
4646
#include "ne_nvme.h"
4747
#include "ne_thermalzone.h"
48+
#include "ne_hwmon.h"
4849

4950
/*
5051
* Update the metrics, this function is invoked every time 'scrape_interval'
@@ -200,6 +201,7 @@ static int in_ne_init(struct flb_input_instance *in,
200201
mk_list_add(&processes_collector._head, &ctx->collectors);
201202
mk_list_add(&nvme_collector._head, &ctx->collectors);
202203
mk_list_add(&thermalzone_collector._head, &ctx->collectors);
204+
mk_list_add(&hwmon_collector._head, &ctx->collectors);
203205

204206
mk_list_foreach(head, &ctx->collectors) {
205207
coll = mk_list_entry(head, struct flb_ne_collector, _head);
@@ -428,6 +430,12 @@ static struct flb_config_map config_map[] = {
428430
"scrape interval to collect nvme metrics from the node."
429431
},
430432

433+
{
434+
FLB_CONFIG_MAP_TIME, "collector.hwmon.scrape_interval", "0",
435+
0, FLB_FALSE, 0,
436+
"scrape interval to collect hwmon metrics from the node."
437+
},
438+
431439
{
432440
FLB_CONFIG_MAP_CLIST, "metrics",
433441
NE_DEFAULT_ENABLED_METRICS,
@@ -503,6 +511,31 @@ static struct flb_config_map config_map[] = {
503511
0, FLB_TRUE, offsetof(struct flb_ne, dt_regex_skip_devices_text),
504512
"ignore regular expression for disk devices"
505513
},
514+
515+
/* hwmon specific settings */
516+
{
517+
FLB_CONFIG_MAP_STR, "collector.hwmon.chip-include", NULL,
518+
0, FLB_TRUE, offsetof(struct flb_ne, hwmon_chip_regex_include_text),
519+
"regex of chips to include"
520+
},
521+
522+
{
523+
FLB_CONFIG_MAP_STR, "collector.hwmon.chip-exclude", NULL,
524+
0, FLB_TRUE, offsetof(struct flb_ne, hwmon_chip_regex_exclude_text),
525+
"regex of chips to exclude"
526+
},
527+
528+
{
529+
FLB_CONFIG_MAP_STR, "collector.hwmon.sensor-include", NULL,
530+
0, FLB_TRUE, offsetof(struct flb_ne, hwmon_sensor_regex_include_text),
531+
"regex of sensors to include"
532+
},
533+
534+
{
535+
FLB_CONFIG_MAP_STR, "collector.hwmon.sensor-exclude", NULL,
536+
0, FLB_TRUE, offsetof(struct flb_ne, hwmon_sensor_regex_exclude_text),
537+
"regex of sensors to exclude"
538+
},
506539
/* EOF */
507540
{0}
508541
};

plugins/in_node_exporter_metrics/ne.h

Lines changed: 17 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"
36+
#define NE_DEFAULT_ENABLED_METRICS "cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,sockstat,filefd,systemd,nvme,thermal_zone,hwmon"
3737
#elif __APPLE__
3838
#define NE_DEFAULT_ENABLED_METRICS "cpu,loadavg,meminfo,diskstats,uname,netdev"
3939
#endif
@@ -233,6 +233,22 @@ struct flb_ne {
233233
struct cmt_gauge *thermalzone_temp;
234234
struct cmt_gauge *cooling_device_cur_state;
235235
struct cmt_gauge *cooling_device_max_state;
236+
237+
/* hwmon */
238+
struct cmt_gauge *hwmon_temp_celsius;
239+
struct cmt_gauge *hwmon_temp_max_celsius;
240+
struct cmt_gauge *hwmon_temp_crit_celsius;
241+
struct cmt_gauge *hwmon_in_volts;
242+
struct cmt_gauge *hwmon_fan_rpm;
243+
struct cmt_gauge *hwmon_power_watts;
244+
flb_sds_t hwmon_chip_regex_include_text;
245+
flb_sds_t hwmon_chip_regex_exclude_text;
246+
flb_sds_t hwmon_sensor_regex_include_text;
247+
flb_sds_t hwmon_sensor_regex_exclude_text;
248+
struct flb_regex *hwmon_chip_regex_include;
249+
struct flb_regex *hwmon_chip_regex_exclude;
250+
struct flb_regex *hwmon_sensor_regex_include;
251+
struct flb_regex *hwmon_sensor_regex_exclude;
236252
};
237253

238254
struct flb_ne_collector {
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-2024 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_hwmon_linux.c"
22+
#else
23+
24+
#include "ne.h"
25+
26+
struct flb_ne_collector hwmon_collector = {
27+
.name = "hwmon",
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-2024 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_HWMON_H
21+
#define FLB_IN_NE_HWMON_H
22+
23+
#include "ne.h"
24+
25+
extern struct flb_ne_collector hwmon_collector;
26+
27+
#endif

0 commit comments

Comments
 (0)