From 98c1d9ceebdbe5694dc3c0cf7277c998175b1b52 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 6 Jun 2023 18:34:38 -0400 Subject: [PATCH 01/13] in_node_exporter_metrics: add support for thermal_zone. Signed-off-by: Phillip Whelan --- .../in_node_exporter_metrics/CMakeLists.txt | 1 + plugins/in_node_exporter_metrics/ne.c | 13 ++ plugins/in_node_exporter_metrics/ne.h | 7 +- .../in_node_exporter_metrics/ne_thermalzone.c | 32 +++ .../in_node_exporter_metrics/ne_thermalzone.h | 28 +++ .../ne_thermalzone_linux.c | 202 ++++++++++++++++++ .../ne_thermalzone_linux.h | 29 +++ plugins/in_node_exporter_metrics/ne_utils.c | 73 +++++++ plugins/in_node_exporter_metrics/ne_utils.h | 6 + 9 files changed, 390 insertions(+), 1 deletion(-) create mode 100644 plugins/in_node_exporter_metrics/ne_thermalzone.c create mode 100644 plugins/in_node_exporter_metrics/ne_thermalzone.h create mode 100644 plugins/in_node_exporter_metrics/ne_thermalzone_linux.c create mode 100644 plugins/in_node_exporter_metrics/ne_thermalzone_linux.h diff --git a/plugins/in_node_exporter_metrics/CMakeLists.txt b/plugins/in_node_exporter_metrics/CMakeLists.txt index 03dde74a36f..ec30f187260 100644 --- a/plugins/in_node_exporter_metrics/CMakeLists.txt +++ b/plugins/in_node_exporter_metrics/CMakeLists.txt @@ -16,6 +16,7 @@ set(src ne_utils.c ne_config.c ne_systemd.c + ne_thermalzone.c ne.c ) diff --git a/plugins/in_node_exporter_metrics/ne.c b/plugins/in_node_exporter_metrics/ne.c index efd12c213c3..7424640afcf 100644 --- a/plugins/in_node_exporter_metrics/ne.c +++ b/plugins/in_node_exporter_metrics/ne.c @@ -43,6 +43,7 @@ #include "ne_systemd.h" #include "ne_processes.h" #include "ne_nvme.h" +#include "ne_thermalzone_linux.h" /* * Update the metrics, this function is invoked every time 'scrape_interval' @@ -192,6 +193,7 @@ static int in_ne_init(struct flb_input_instance *in, mk_list_add(&systemd_collector._head, &ctx->collectors); mk_list_add(&processes_collector._head, &ctx->collectors); mk_list_add(&nvme_collector._head, &ctx->collectors); + mk_list_add(&thermalzone_collector._head, &ctx->collectors); mk_list_foreach(head, &ctx->collectors) { coll = mk_list_entry(head, struct flb_ne_collector, _head); @@ -287,6 +289,9 @@ static void in_ne_pause(void *data, struct flb_config *config) } flb_input_collector_pause(coll->coll_fd, ctx->ins); } + if (ctx->coll_thermalzone_fd != -1) { + flb_input_collector_pause(ctx->coll_systemd_fd, ctx->ins); + } } static void in_ne_resume(void *data, struct flb_config *config) @@ -303,6 +308,9 @@ static void in_ne_resume(void *data, struct flb_config *config) } flb_input_collector_resume(coll->coll_fd, ctx->ins); } + if (ctx->coll_thermalzone_fd != -1) { + flb_input_collector_resume(ctx->coll_systemd_fd, ctx->ins); + } } /* Configuration properties map */ @@ -402,6 +410,11 @@ static struct flb_config_map config_map[] = { 0, FLB_FALSE, 0, "scrape interval to collect processes metrics from the node." }, + { + FLB_CONFIG_MAP_TIME, "collector.thermalzone.scrape_interval", "0", + 0, FLB_FALSE, 0, + "scrape interval to collect thermal zone metrics from the node." + }, { FLB_CONFIG_MAP_TIME, "collector.nvme.scrape_interval", "0", diff --git a/plugins/in_node_exporter_metrics/ne.h b/plugins/in_node_exporter_metrics/ne.h index e6c627e3d2d..6f8ae328704 100644 --- a/plugins/in_node_exporter_metrics/ne.h +++ b/plugins/in_node_exporter_metrics/ne.h @@ -33,7 +33,7 @@ /* Default enabled metrics */ #ifdef __linux__ -#define NE_DEFAULT_ENABLED_METRICS "cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,filefd,systemd,nvme" +#define NE_DEFAULT_ENABLED_METRICS "cpu,cpufreq,meminfo,diskstats,filesystem,uname,stat,time,loadavg,vmstat,netdev,filefd,systemd,nvme,thermal_zone" #elif __APPLE__ #define NE_DEFAULT_ENABLED_METRICS "cpu,loadavg,meminfo,diskstats,uname,netdev" #endif @@ -206,6 +206,11 @@ struct flb_ne { /* nvme */ struct cmt_gauge *nvme_info; + + /* thermal zone */ + struct cmt_gauge *thermalzone_temp; + struct cmt_gauge *cooling_device_cur_state; + struct cmt_gauge *cooling_device_max_state; }; struct flb_ne_collector { diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone.c b/plugins/in_node_exporter_metrics/ne_thermalzone.c new file mode 100644 index 00000000000..3b6eae2d457 --- /dev/null +++ b/plugins/in_node_exporter_metrics/ne_thermalzone.c @@ -0,0 +1,32 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2023 The Fluent Bit Authors + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef __linux__ +#include "ne_thermalzone_linux.c" +#else + +#include "ne.h" + +struct flb_ne_collector thermalzone_collector = { + .name = "thermalzone", + .cb_init = NULL, + .cb_update = NULL, + .cb_exit = NULL +}; +#endif diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone.h b/plugins/in_node_exporter_metrics/ne_thermalzone.h new file mode 100644 index 00000000000..cc227c05777 --- /dev/null +++ b/plugins/in_node_exporter_metrics/ne_thermalzone.h @@ -0,0 +1,28 @@ + +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2023 The Fluent Bit Authors + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLB_IN_NE_THERMALZONE_H +#define FLB_IN_NE_THERMALZONE_H + +#include "ne.h" + +extern struct flb_ne_collector thermalzone_collector; + +#endif diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c new file mode 100644 index 00000000000..5c1d930380d --- /dev/null +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -0,0 +1,202 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2015-2022 The Fluent Bit Authors + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "ne.h" +#include "ne_utils.h" + +#include + +/* + * See kernel documentation for a description: + * https://www.kernel.org/doc/html/latest/filesystems/proc.html + * + * user: normal processes executing in user mode + * nice: niced processes executing in user mode + * system: processes executing in kernel mode + * idle: twiddling thumbs + * iowait: In a word, iowait stands for waiting for I/O to complete. But there are several problems: + * irq: servicing interrupts + * softirq: servicing softirqs + * steal: involuntary wait + * guest: running a normal guest + * guest_nice: running a niced guest + * + * Ensure to pick the correct version of the documentation, older versions here: + * https://github.com/torvalds/linux/tree/master/Documentation + */ +/* + * Thermal zone stats, reads /sys/class/thermal/thermal_zone* + * ---------------------------------------------------------- + */ + +int ne_thermalzone_init(struct flb_ne *ctx) +{ + struct cmt_gauge *g; + + g = cmt_gauge_create(ctx->cmt, "node", "thermal_zone", "temp", + "Zone temperature in Celsius", + 2, (char *[]) {"zone", "type"}); + if (!g) { + flb_plg_error(ctx->ins, "could not initialize thermal zone metrics"); + return -1; + } + ctx->thermalzone_temp = g; + + g = cmt_gauge_create(ctx->cmt, "node", "cooling_device", "cur_state", + "Current throttle state of the cooling device", + 2, (char *[]) {"name", "type"}); + if (!g) { + flb_plg_error(ctx->ins, "could not initialize cooling device cur_state metric"); + return -1; + } + ctx->cooling_device_cur_state = g; + + g = cmt_gauge_create(ctx->cmt, "node", "cooling_device", "max_state", + "Maximum throttle state of the cooling device", + 2, (char *[]) {"name", "type"}); + if (!g) { + flb_plg_error(ctx->ins, "could not initialize cooling device max_state metric"); + return -1; + } + ctx->cooling_device_max_state = g; + return 0; +} + +int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) +{ + uint64_t ts; + int ret; + uint64_t temp = 0; + struct mk_list *head; + struct mk_list list; + struct flb_slist_entry *entry; + flb_sds_t type; + const char *pattern = "/class/thermal/thermal_zone[0-9]*"; + + ts = cfl_time_now(); + + ret = ne_utils_path_scan(ctx, ctx->path_sysfs, pattern, NE_SCAN_DIR, &list); + if (ret != 0) { + return -1; + } + + if (mk_list_size(&list) == 0) { + return 0; + } + + /* Process entries */ + mk_list_foreach(head, &list) { + entry = mk_list_entry(head, struct flb_slist_entry, _head); + + /* Core ID */ + ret = ne_utils_file_read_uint64(ctx->path_sysfs, + entry->str, + "temp", NULL, + &temp); + if (ret != 0) { + continue; + } + + ret = ne_utils_file_read_sds(ctx->path_sysfs, entry->str, "type", NULL, &type); + if (ret != 0) { + flb_plg_error(ctx->ins, "unable to get type for zone: %s", entry->str); + continue; + } + + cmt_gauge_set(ctx->thermalzone_temp, ts, ((double)temp)/1000.0, + 2, (char *[]) {&entry->str[strlen("/sys/class/thermal/thermal_zone")], type}); + flb_sds_destroy(type); + } + + flb_slist_destroy(&list); + + return 0; +} + +int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) +{ + uint64_t ts; + int ret; + uint64_t cur_state = 0; + uint64_t max_state = 0; + struct mk_list *head; + struct mk_list list; + struct flb_slist_entry *entry; + flb_sds_t type; + const char *pattern = "/class/thermal/cooling_device[0-9]*"; + /* Status arrays */ + uint64_t core_throttles_set[32][256]; + uint64_t package_throttles_set[32]; + + ts = cfl_time_now(); + + ret = ne_utils_path_scan(ctx, ctx->path_sysfs, pattern, NE_SCAN_DIR, &list); + if (ret != 0) { + return -1; + } + + if (mk_list_size(&list) == 0) { + return 0; + } + + /* Reset arrays status */ + memset(&core_throttles_set, 0, sizeof(core_throttles_set)); + memset(&package_throttles_set, 0, sizeof(package_throttles_set)); + + /* Process entries */ + mk_list_foreach(head, &list) { + entry = mk_list_entry(head, struct flb_slist_entry, _head); + + /* Core ID */ + ret = ne_utils_file_read_uint64(ctx->path_sysfs, + entry->str, + "cur_state", NULL, + &cur_state); + if (ret != 0) { + continue; + } + + ret = ne_utils_file_read_uint64(ctx->path_sysfs, + entry->str, + "max_state", NULL, + &max_state); + if (ret != 0) { + continue; + } + + ret = ne_utils_file_read_sds(ctx->path_sysfs, entry->str, "type", NULL, &type); + if (ret != 0) { + flb_plg_error(ctx->ins, "unable to get type for zone: %s", entry->str); + continue; + } + + cmt_gauge_set(ctx->cooling_device_cur_state, ts, ((double)cur_state), + 2, (char *[]) {&entry->str[strlen("/sys/class/thermal/cooling_device")], type}); + cmt_gauge_set(ctx->cooling_device_max_state, ts, ((double)max_state), + 2, (char *[]) {&entry->str[strlen("/sys/class/thermal/cooling_device")], type}); + flb_sds_destroy(type); + } + + flb_slist_destroy(&list); + + return 0; +} \ No newline at end of file diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h new file mode 100644 index 00000000000..ce5f719ce4b --- /dev/null +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2015-2022 The Fluent Bit Authors + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLB_IN_NE_THERMALZONE_LINUX_H +#define FLB_IN_NE_THERMALZONE_LINUX_H + +#include "ne.h" + +int ne_thermalzone_init(struct flb_ne *ctx); +int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx); +int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx); + +#endif // FLB_IN_NE_THERMALZONE_LINUX_H diff --git a/plugins/in_node_exporter_metrics/ne_utils.c b/plugins/in_node_exporter_metrics/ne_utils.c index 54cb2e2da1c..9d1bbc5829b 100644 --- a/plugins/in_node_exporter_metrics/ne_utils.c +++ b/plugins/in_node_exporter_metrics/ne_utils.c @@ -178,6 +178,79 @@ int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list return 0; } +/* + * Read a file and every non-empty line is stored as a flb_slist_entry in the + * given list. + */ +int ne_utils_file_read_sds(const char *mount, + const char *path, + const char *join_a, + const char *join_b, + flb_sds_t *str) +{ + int fd; + int len; + int i; + flb_sds_t p; + ssize_t bytes; + char tmp[32]; + + /* Check the path starts with the mount point to prevent duplication. */ + if (strncasecmp(path, mount, strlen(mount)) == 0 && + path[strlen(mount)] == '/') { + mount = ""; + } + + /* Compose the final path */ + p = flb_sds_create(mount); + if (!p) { + return -1; + } + + len = strlen(path); + flb_sds_cat_safe(&p, path, len); + + if (join_a) { + flb_sds_cat_safe(&p, "/", 1); + len = strlen(join_a); + flb_sds_cat_safe(&p, join_a, len); + } + + if (join_b) { + flb_sds_cat_safe(&p, "/", 1); + len = strlen(join_b); + flb_sds_cat_safe(&p, join_b, len); + } + + fd = open(p, O_RDONLY); + if (fd == -1) { + flb_sds_destroy(p); + return -1; + } + flb_sds_destroy(p); + + bytes = read(fd, &tmp, sizeof(tmp)); + if (bytes == -1) { + flb_errno(); + close(fd); + return -1; + } + close(fd); + + for (i = bytes-1; i > 0; i--) { + if (tmp[i] != '\n' && tmp[i] != '\r') { + break; + } + } + + *str = flb_sds_create_len(tmp, i+1); + if (*str == NULL) { + return -1; + } + + return 0; +} + int ne_utils_path_scan(struct flb_ne *ctx, const char *mount, const char *path, int expected, struct mk_list *list) { diff --git a/plugins/in_node_exporter_metrics/ne_utils.h b/plugins/in_node_exporter_metrics/ne_utils.h index 448293a033a..c94d4f7d718 100644 --- a/plugins/in_node_exporter_metrics/ne_utils.h +++ b/plugins/in_node_exporter_metrics/ne_utils.h @@ -33,6 +33,12 @@ int ne_utils_file_read_uint64(const char *mount, const char *join_a, const char *join_b, uint64_t *out_val); +int ne_utils_file_read_sds(const char *mount, + const char *path, + const char *join_a, + const char *join_b, + flb_sds_t *str); + int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list *list); int ne_utils_path_scan(struct flb_ne *ctx, const char *mount, const char *path, int expected, struct mk_list *list); From de3af86b599e0c0e1355eb884f3b27f41a34efdb Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 6 Jun 2023 19:50:20 -0400 Subject: [PATCH 02/13] in_node_exporter_metrics: make zone naming code safer. Signed-off-by: Phillip Whelan --- .../ne_thermalzone_linux.c | 62 +++++++++++++++---- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index 5c1d930380d..e9066789aef 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -25,6 +25,10 @@ #include +#define THERMAL_ZONE_PATTERN "/class/thermal/thermal_zone" +#define COOLING_DEVICE_PATTERN "/class/thermal/cooling_device" + + /* * See kernel documentation for a description: * https://www.kernel.org/doc/html/latest/filesystems/proc.html @@ -90,16 +94,29 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) struct mk_list list; struct flb_slist_entry *entry; flb_sds_t type; - const char *pattern = "/class/thermal/thermal_zone[0-9]*"; + flb_sds_t syspfx = flb_sds_create_size(strlen(THERMAL_ZONE_PATTERN) + + strlen(ctx->path_sysfs) + 8); + char *num; + const char *pattern = THERMAL_ZONE_PATTERN "[0-9]*"; ts = cfl_time_now(); + if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { + flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)-1); + } else { + flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)); + } + flb_sds_cat_safe(&syspfx, THERMAL_ZONE_PATTERN, + strlen(THERMAL_ZONE_PATTERN)); + ret = ne_utils_path_scan(ctx, ctx->path_sysfs, pattern, NE_SCAN_DIR, &list); if (ret != 0) { + flb_sds_destroy(syspfx); return -1; } if (mk_list_size(&list) == 0) { + flb_sds_destroy(syspfx); return 0; } @@ -122,12 +139,20 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) continue; } + if (strncmp(entry->str, syspfx, strlen(syspfx)) == 0) { + num = &entry->str[strlen(syspfx)]; + } else { + num = entry->str; + } + cmt_gauge_set(ctx->thermalzone_temp, ts, ((double)temp)/1000.0, - 2, (char *[]) {&entry->str[strlen("/sys/class/thermal/thermal_zone")], type}); + 2, (char *[]) {num, type}); + flb_sds_destroy(type); } flb_slist_destroy(&list); + flb_sds_destroy(syspfx); return 0; } @@ -142,26 +167,34 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) struct mk_list list; struct flb_slist_entry *entry; flb_sds_t type; + char *num; + flb_sds_t syspfx = flb_sds_create_size(strlen(COOLING_DEVICE_PATTERN) + + strlen(ctx->path_sysfs) + 8); const char *pattern = "/class/thermal/cooling_device[0-9]*"; - /* Status arrays */ - uint64_t core_throttles_set[32][256]; - uint64_t package_throttles_set[32]; + ts = cfl_time_now(); + if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { + flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)-1); + } else { + flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)); + } + flb_sds_cat_safe(&syspfx, COOLING_DEVICE_PATTERN, + strlen(COOLING_DEVICE_PATTERN)); + + ret = ne_utils_path_scan(ctx, ctx->path_sysfs, pattern, NE_SCAN_DIR, &list); if (ret != 0) { + flb_sds_destroy(syspfx); return -1; } if (mk_list_size(&list) == 0) { + flb_sds_destroy(syspfx); return 0; } - /* Reset arrays status */ - memset(&core_throttles_set, 0, sizeof(core_throttles_set)); - memset(&package_throttles_set, 0, sizeof(package_throttles_set)); - /* Process entries */ mk_list_foreach(head, &list) { entry = mk_list_entry(head, struct flb_slist_entry, _head); @@ -189,14 +222,21 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) continue; } + if (strncmp(entry->str, syspfx, strlen(syspfx)) == 0) { + num = &entry->str[strlen(syspfx)]; + } else { + num = entry->str; + } + cmt_gauge_set(ctx->cooling_device_cur_state, ts, ((double)cur_state), - 2, (char *[]) {&entry->str[strlen("/sys/class/thermal/cooling_device")], type}); + 2, (char *[]) {num, type}); cmt_gauge_set(ctx->cooling_device_max_state, ts, ((double)max_state), - 2, (char *[]) {&entry->str[strlen("/sys/class/thermal/cooling_device")], type}); + 2, (char *[]) {num, type}); flb_sds_destroy(type); } flb_slist_destroy(&list); + flb_sds_destroy(syspfx); return 0; } \ No newline at end of file From 599cbdd8eedc426ec3215be6d14111bb81231744 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 13 Jun 2023 19:06:29 -0400 Subject: [PATCH 03/13] in_node_exporter_metrics: update documentation for thermal_zone. Signed-off-by: Phillip Whelan --- .../in_node_exporter_metrics/ne_thermalzone_linux.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index e9066789aef..d2b5c7bbfcc 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -31,18 +31,7 @@ /* * See kernel documentation for a description: - * https://www.kernel.org/doc/html/latest/filesystems/proc.html - * - * user: normal processes executing in user mode - * nice: niced processes executing in user mode - * system: processes executing in kernel mode - * idle: twiddling thumbs - * iowait: In a word, iowait stands for waiting for I/O to complete. But there are several problems: - * irq: servicing interrupts - * softirq: servicing softirqs - * steal: involuntary wait - * guest: running a normal guest - * guest_nice: running a niced guest + * https://www.kernel.org/doc/html/latest/driver-api/thermal/sysfs-api.html * * Ensure to pick the correct version of the documentation, older versions here: * https://github.com/torvalds/linux/tree/master/Documentation From 6bc5b0429b726da85face98e478986d635c4f465 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 13 Jun 2023 19:12:34 -0400 Subject: [PATCH 04/13] in_node_exporter_metrics: remove temp var used for init of thermal_zone gauges. Signed-off-by: Phillip Whelan --- .../ne_thermalzone_linux.c | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index d2b5c7bbfcc..2a99baf4f24 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -43,34 +43,32 @@ int ne_thermalzone_init(struct flb_ne *ctx) { - struct cmt_gauge *g; - - g = cmt_gauge_create(ctx->cmt, "node", "thermal_zone", "temp", - "Zone temperature in Celsius", - 2, (char *[]) {"zone", "type"}); - if (!g) { + ctx->thermalzone_temp = cmt_gauge_create(ctx->cmt, "node", "thermal_zone", "temp", + "Zone temperature in Celsius", + 2, (char *[]) {"zone", "type"}); + if (!ctx->thermalzone_temp) { flb_plg_error(ctx->ins, "could not initialize thermal zone metrics"); return -1; } - ctx->thermalzone_temp = g; - g = cmt_gauge_create(ctx->cmt, "node", "cooling_device", "cur_state", - "Current throttle state of the cooling device", - 2, (char *[]) {"name", "type"}); - if (!g) { + ctx->cooling_device_cur_state = cmt_gauge_create(ctx->cmt, + "node", "cooling_device", "cur_state", + "Current throttle state of the cooling device", + 2, (char *[]) {"name", "type"}); + if (!ctx->cooling_device_cur_state) { flb_plg_error(ctx->ins, "could not initialize cooling device cur_state metric"); return -1; } - ctx->cooling_device_cur_state = g; - g = cmt_gauge_create(ctx->cmt, "node", "cooling_device", "max_state", - "Maximum throttle state of the cooling device", - 2, (char *[]) {"name", "type"}); - if (!g) { + ctx->cooling_device_max_state = cmt_gauge_create(ctx->cmt, + "node", "cooling_device", "max_state", + "Maximum throttle state of the cooling device", + 2, (char *[]) {"name", "type"}); + if (!ctx->cooling_device_max_state) { flb_plg_error(ctx->ins, "could not initialize cooling device max_state metric"); return -1; } - ctx->cooling_device_max_state = g; + return 0; } From 4a180f3f0cd978c6d07dc9b2dd35c5c2fd5b8e65 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 13 Jun 2023 19:38:58 -0400 Subject: [PATCH 05/13] in_node_exporter_metrics: fix prefix removal code for gauges in thermal_zone. Signed-off-by: Phillip Whelan --- .../ne_thermalzone_linux.c | 105 +++++++++++------- .../ne_thermalzone_linux.h | 7 +- 2 files changed, 69 insertions(+), 43 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index 2a99baf4f24..c6743618863 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -22,13 +22,10 @@ #include "ne.h" #include "ne_utils.h" +#include "ne_thermalzone_linux.h" #include -#define THERMAL_ZONE_PATTERN "/class/thermal/thermal_zone" -#define COOLING_DEVICE_PATTERN "/class/thermal/cooling_device" - - /* * See kernel documentation for a description: * https://www.kernel.org/doc/html/latest/driver-api/thermal/sysfs-api.html @@ -81,32 +78,47 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) struct mk_list list; struct flb_slist_entry *entry; flb_sds_t type; - flb_sds_t syspfx = flb_sds_create_size(strlen(THERMAL_ZONE_PATTERN) + - strlen(ctx->path_sysfs) + 8); + flb_sds_t full_path_sysfs; + int path_sysfs_len; char *num; - const char *pattern = THERMAL_ZONE_PATTERN "[0-9]*"; ts = cfl_time_now(); - if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { - flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)-1); - } else { - flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)); - } - flb_sds_cat_safe(&syspfx, THERMAL_ZONE_PATTERN, - strlen(THERMAL_ZONE_PATTERN)); - - ret = ne_utils_path_scan(ctx, ctx->path_sysfs, pattern, NE_SCAN_DIR, &list); + ret = ne_utils_path_scan(ctx, ctx->path_sysfs, THERMAL_ZONE_PATTERN, NE_SCAN_DIR, &list); if (ret != 0) { - flb_sds_destroy(syspfx); return -1; } if (mk_list_size(&list) == 0) { - flb_sds_destroy(syspfx); return 0; } + full_path_sysfs = flb_sds_create_size(strlen(THERMAL_ZONE_BASE) + + strlen(ctx->path_sysfs) + 8); + if (full_path_sysfs == NULL) { + flb_slist_destroy(&list); + return -1; + } + path_sysfs_len = strlen(ctx->path_sysfs); + if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { + path_sysfs_len--; + } + path_sysfs_len = strlen(ctx->path_sysfs); + if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { + path_sysfs_len--; + } + if (flb_sds_cat_safe(&full_path_sysfs, ctx->path_sysfs, path_sysfs_len) < 0) { + flb_slist_destroy(&list); + flb_sds_destroy(full_path_sysfs); + return -1; + } + if (flb_sds_cat_safe(&full_path_sysfs, THERMAL_ZONE_BASE, + strlen(THERMAL_ZONE_BASE)) < 0) { + flb_slist_destroy(&list); + flb_sds_destroy(full_path_sysfs); + return -1; + } + /* Process entries */ mk_list_foreach(head, &list) { entry = mk_list_entry(head, struct flb_slist_entry, _head); @@ -126,20 +138,20 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) continue; } - if (strncmp(entry->str, syspfx, strlen(syspfx)) == 0) { - num = &entry->str[strlen(syspfx)]; + if (strncmp(entry->str, full_path_sysfs, strlen(full_path_sysfs)) == 0) { + num = &entry->str[strlen(full_path_sysfs)]; } else { num = entry->str; } - cmt_gauge_set(ctx->thermalzone_temp, ts, ((double)temp)/1000.0, + cmt_gauge_set(ctx->thermalzone_temp, ts, ((double) temp)/1000.0, 2, (char *[]) {num, type}); flb_sds_destroy(type); } flb_slist_destroy(&list); - flb_sds_destroy(syspfx); + flb_sds_destroy(full_path_sysfs); return 0; } @@ -155,33 +167,42 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) struct flb_slist_entry *entry; flb_sds_t type; char *num; - flb_sds_t syspfx = flb_sds_create_size(strlen(COOLING_DEVICE_PATTERN) + - strlen(ctx->path_sysfs) + 8); - const char *pattern = "/class/thermal/cooling_device[0-9]*"; - + flb_sds_t full_path_sysfs; + int path_sysfs_len; ts = cfl_time_now(); - if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { - flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)-1); - } else { - flb_sds_cat_safe(&syspfx, ctx->path_sysfs, strlen(ctx->path_sysfs)); - } - flb_sds_cat_safe(&syspfx, COOLING_DEVICE_PATTERN, - strlen(COOLING_DEVICE_PATTERN)); - - - ret = ne_utils_path_scan(ctx, ctx->path_sysfs, pattern, NE_SCAN_DIR, &list); + ret = ne_utils_path_scan(ctx, ctx->path_sysfs, COOLING_DEVICE_PATTERN, NE_SCAN_DIR, &list); if (ret != 0) { - flb_sds_destroy(syspfx); return -1; } if (mk_list_size(&list) == 0) { - flb_sds_destroy(syspfx); return 0; } + full_path_sysfs = flb_sds_create_size(strlen(COOLING_DEVICE_BASE) + + strlen(ctx->path_sysfs) + 8); + if (full_path_sysfs == NULL) { + flb_slist_destroy(&list); + return -1; + } + path_sysfs_len = strlen(ctx->path_sysfs); + if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { + path_sysfs_len--; + } + if (flb_sds_cat_safe(&full_path_sysfs, ctx->path_sysfs, path_sysfs_len) < 0) { + flb_slist_destroy(&list); + flb_sds_destroy(full_path_sysfs); + return -1; + } + if (flb_sds_cat_safe(&full_path_sysfs, COOLING_DEVICE_BASE, + strlen(COOLING_DEVICE_BASE)) < 0) { + flb_slist_destroy(&list); + flb_sds_destroy(full_path_sysfs); + return -1; + } + /* Process entries */ mk_list_foreach(head, &list) { entry = mk_list_entry(head, struct flb_slist_entry, _head); @@ -209,8 +230,8 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) continue; } - if (strncmp(entry->str, syspfx, strlen(syspfx)) == 0) { - num = &entry->str[strlen(syspfx)]; + if (strncmp(entry->str, full_path_sysfs, strlen(full_path_sysfs)) == 0) { + num = &entry->str[strlen(full_path_sysfs)]; } else { num = entry->str; } @@ -223,7 +244,7 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) } flb_slist_destroy(&list); - flb_sds_destroy(syspfx); + flb_sds_destroy(full_path_sysfs); return 0; -} \ No newline at end of file +} diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h index ce5f719ce4b..a6d69074e51 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h @@ -22,8 +22,13 @@ #include "ne.h" +#define THERMAL_ZONE_BASE "/class/thermal/thermal_zone" +#define THERMAL_ZONE_PATTERN THERMAL_ZONE_BASE "[0-9]*" +#define COOLING_DEVICE_BASE "/class/thermal/cooling_device" +#define COOLING_DEVICE_PATTERN COOLING_DEVICE_BASE "[0-9]*" + int ne_thermalzone_init(struct flb_ne *ctx); int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx); int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx); -#endif // FLB_IN_NE_THERMALZONE_LINUX_H +#endif From d9ee8f5858fd2187cbb88c39ce48adcb5351ba95 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 13 Jun 2023 19:44:44 -0400 Subject: [PATCH 06/13] in_node_exporter_metrics: check return values in ne_utils_file_read_sds. Signed-off-by: Phillip Whelan --- plugins/in_node_exporter_metrics/ne_utils.c | 35 ++++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_utils.c b/plugins/in_node_exporter_metrics/ne_utils.c index 9d1bbc5829b..027da275929 100644 --- a/plugins/in_node_exporter_metrics/ne_utils.c +++ b/plugins/in_node_exporter_metrics/ne_utils.c @@ -179,14 +179,13 @@ int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list } /* - * Read a file and every non-empty line is stored as a flb_slist_entry in the - * given list. + * Read a file and store the first line as a string. */ int ne_utils_file_read_sds(const char *mount, const char *path, - const char *join_a, - const char *join_b, - flb_sds_t *str) + const char *join_a, + const char *join_b, + flb_sds_t *str) { int fd; int len; @@ -211,15 +210,27 @@ int ne_utils_file_read_sds(const char *mount, flb_sds_cat_safe(&p, path, len); if (join_a) { - flb_sds_cat_safe(&p, "/", 1); + if (flb_sds_cat_safe(&p, "/", 1) < 0) { + flb_sds_destroy(p); + return -1; + } len = strlen(join_a); - flb_sds_cat_safe(&p, join_a, len); + if (flb_sds_cat_safe(&p, join_a, len) < 0) { + flb_sds_destroy(p); + return -1; + } } if (join_b) { - flb_sds_cat_safe(&p, "/", 1); + if (flb_sds_cat_safe(&p, "/", 1) < 0) { + flb_sds_destroy(p); + return -1; + } len = strlen(join_b); - flb_sds_cat_safe(&p, join_b, len); + if (flb_sds_cat_safe(&p, join_b, len) < 0) { + flb_sds_destroy(p); + return -1; + } } fd = open(p, O_RDONLY); @@ -238,9 +249,9 @@ int ne_utils_file_read_sds(const char *mount, close(fd); for (i = bytes-1; i > 0; i--) { - if (tmp[i] != '\n' && tmp[i] != '\r') { - break; - } + if (tmp[i] != '\n' && tmp[i] != '\r') { + break; + } } *str = flb_sds_create_len(tmp, i+1); From 8e5546a1feec8a3cf1421d05145ebf683a406e1c Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Fri, 7 Jul 2023 11:27:36 -0400 Subject: [PATCH 07/13] in_node_exporter_metrics: check return code for flb_sds_cat_safe. Signed-off-by: Phillip Whelan --- plugins/in_node_exporter_metrics/ne_utils.c | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_utils.c b/plugins/in_node_exporter_metrics/ne_utils.c index 027da275929..f3034076270 100644 --- a/plugins/in_node_exporter_metrics/ne_utils.c +++ b/plugins/in_node_exporter_metrics/ne_utils.c @@ -91,18 +91,33 @@ int ne_utils_file_read_uint64(const char *mount, } len = strlen(path); - flb_sds_cat_safe(&p, path, len); + if (flb_sds_cat_safe(&p, path, len) < 0) { + flb_sds_destroy(p); + return -1; + } if (join_a) { - flb_sds_cat_safe(&p, "/", 1); + if (flb_sds_cat_safe(&p, "/", 1) < 0) { + flb_sds_destroy(p); + return -1; + } len = strlen(join_a); - flb_sds_cat_safe(&p, join_a, len); + if (flb_sds_cat_safe(&p, join_a, len) < 0) { + flb_sds_destroy(p); + return -1; + } } if (join_b) { - flb_sds_cat_safe(&p, "/", 1); + if (flb_sds_cat_safe(&p, "/", 1) < 0) { + flb_sds_destroy(p); + return -1; + } len = strlen(join_b); - flb_sds_cat_safe(&p, join_b, len); + if (flb_sds_cat_safe(&p, join_b, len) < 0) { + flb_sds_destroy(p); + return -1; + } } fd = open(p, O_RDONLY); From f53f790ce6831963c499dd1dde1b7014bb3a118c Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 8 Aug 2023 18:58:01 -0400 Subject: [PATCH 08/13] in_node_exporter_metrics: remove redundant code, clarify code that looks possibly redundant with comments. Signed-off-by: Phillip Whelan --- plugins/in_node_exporter_metrics/ne_thermalzone_linux.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index c6743618863..878a6ea57fd 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -103,15 +103,13 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { path_sysfs_len--; } - path_sysfs_len = strlen(ctx->path_sysfs); - if (ctx->path_sysfs[strlen(ctx->path_sysfs)-1] == '/') { - path_sysfs_len--; - } + /* Set the full_path to the sysfs path */ if (flb_sds_cat_safe(&full_path_sysfs, ctx->path_sysfs, path_sysfs_len) < 0) { flb_slist_destroy(&list); flb_sds_destroy(full_path_sysfs); return -1; } + /* Concatenate the base for all thermalzone objects */ if (flb_sds_cat_safe(&full_path_sysfs, THERMAL_ZONE_BASE, strlen(THERMAL_ZONE_BASE)) < 0) { flb_slist_destroy(&list); From d2e75680bbd90cff6f7f3f5064d0fa44ed9c1a88 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 8 Aug 2023 19:02:36 -0400 Subject: [PATCH 09/13] in_node_exporter_metrics: rename the ts variable for timestamps to tstamp. Signed-off-by: Phillip Whelan --- .../ne_thermalzone_linux.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index 878a6ea57fd..aaa545ef162 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -71,7 +71,7 @@ int ne_thermalzone_init(struct flb_ne *ctx) int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) { - uint64_t ts; + uint64_t tstamp; int ret; uint64_t temp = 0; struct mk_list *head; @@ -82,7 +82,7 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) int path_sysfs_len; char *num; - ts = cfl_time_now(); + tstamp = cfl_time_now(); ret = ne_utils_path_scan(ctx, ctx->path_sysfs, THERMAL_ZONE_PATTERN, NE_SCAN_DIR, &list); if (ret != 0) { @@ -142,7 +142,7 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) num = entry->str; } - cmt_gauge_set(ctx->thermalzone_temp, ts, ((double) temp)/1000.0, + cmt_gauge_set(ctx->thermalzone_temp, tstamp, ((double) temp)/1000.0, 2, (char *[]) {num, type}); flb_sds_destroy(type); @@ -156,7 +156,7 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) { - uint64_t ts; + uint64_t tstamp; int ret; uint64_t cur_state = 0; uint64_t max_state = 0; @@ -168,7 +168,7 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) flb_sds_t full_path_sysfs; int path_sysfs_len; - ts = cfl_time_now(); + tstamp = cfl_time_now(); ret = ne_utils_path_scan(ctx, ctx->path_sysfs, COOLING_DEVICE_PATTERN, NE_SCAN_DIR, &list); if (ret != 0) { @@ -234,9 +234,9 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) num = entry->str; } - cmt_gauge_set(ctx->cooling_device_cur_state, ts, ((double)cur_state), + cmt_gauge_set(ctx->cooling_device_cur_state, tstamp, ((double)cur_state), 2, (char *[]) {num, type}); - cmt_gauge_set(ctx->cooling_device_max_state, ts, ((double)max_state), + cmt_gauge_set(ctx->cooling_device_max_state, tstamp, ((double)max_state), 2, (char *[]) {num, type}); flb_sds_destroy(type); } From d30348aecd3c50f5e65eddb227b9133a5e7ae7ae Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Thu, 31 Aug 2023 11:44:58 -0400 Subject: [PATCH 10/13] in_node_exporter_metrics: style fix for thermal_zone prototype. Signed-off-by: Phillip Whelan --- plugins/in_node_exporter_metrics/ne_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_utils.h b/plugins/in_node_exporter_metrics/ne_utils.h index c94d4f7d718..50d0937be3f 100644 --- a/plugins/in_node_exporter_metrics/ne_utils.h +++ b/plugins/in_node_exporter_metrics/ne_utils.h @@ -36,8 +36,8 @@ int ne_utils_file_read_uint64(const char *mount, int ne_utils_file_read_sds(const char *mount, const char *path, const char *join_a, - const char *join_b, - flb_sds_t *str); + const char *join_b, + flb_sds_t *str); int ne_utils_file_read_lines(const char *mount, const char *path, struct mk_list *list); int ne_utils_path_scan(struct flb_ne *ctx, const char *mount, const char *path, From f497ee08479ce2e6f168a32fd222432036a9dd33 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 23 Oct 2023 11:02:07 -0300 Subject: [PATCH 11/13] in_node_exporter_metrics: thermalzone: add skeleton for non-linux OSes. Signed-off-by: Phillip Whelan --- plugins/in_node_exporter_metrics/ne.c | 2 +- plugins/in_node_exporter_metrics/ne_thermalzone.h | 1 - plugins/in_node_exporter_metrics/ne_thermalzone_linux.h | 4 ---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne.c b/plugins/in_node_exporter_metrics/ne.c index 7424640afcf..93b0298cbd8 100644 --- a/plugins/in_node_exporter_metrics/ne.c +++ b/plugins/in_node_exporter_metrics/ne.c @@ -43,7 +43,7 @@ #include "ne_systemd.h" #include "ne_processes.h" #include "ne_nvme.h" -#include "ne_thermalzone_linux.h" +#include "ne_thermalzone.h" /* * Update the metrics, this function is invoked every time 'scrape_interval' diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone.h b/plugins/in_node_exporter_metrics/ne_thermalzone.h index cc227c05777..fa335cefeca 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone.h +++ b/plugins/in_node_exporter_metrics/ne_thermalzone.h @@ -1,4 +1,3 @@ - /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Fluent Bit diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h index a6d69074e51..83cb248acbb 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.h @@ -27,8 +27,4 @@ #define COOLING_DEVICE_BASE "/class/thermal/cooling_device" #define COOLING_DEVICE_PATTERN COOLING_DEVICE_BASE "[0-9]*" -int ne_thermalzone_init(struct flb_ne *ctx); -int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx); -int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx); - #endif From 7fdf945274c6c30efcb82206296e4ed5514c8131 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 6 Nov 2023 20:34:30 -0300 Subject: [PATCH 12/13] in_node_exporter_metrics: thermal_zone: remove code dragged along from rebase. Signed-off-by: Phillip Whelan --- plugins/in_node_exporter_metrics/ne.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne.c b/plugins/in_node_exporter_metrics/ne.c index 93b0298cbd8..411bec43399 100644 --- a/plugins/in_node_exporter_metrics/ne.c +++ b/plugins/in_node_exporter_metrics/ne.c @@ -289,9 +289,6 @@ static void in_ne_pause(void *data, struct flb_config *config) } flb_input_collector_pause(coll->coll_fd, ctx->ins); } - if (ctx->coll_thermalzone_fd != -1) { - flb_input_collector_pause(ctx->coll_systemd_fd, ctx->ins); - } } static void in_ne_resume(void *data, struct flb_config *config) @@ -308,9 +305,6 @@ static void in_ne_resume(void *data, struct flb_config *config) } flb_input_collector_resume(coll->coll_fd, ctx->ins); } - if (ctx->coll_thermalzone_fd != -1) { - flb_input_collector_resume(ctx->coll_systemd_fd, ctx->ins); - } } /* Configuration properties map */ From f9191af92d13ed2344de2850befd07489c455fe1 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 6 Nov 2023 20:36:42 -0300 Subject: [PATCH 13/13] in_node_exporter_metrics: thermal_zone: define the new collector for thermal_zone. Signed-off-by: Phillip Whelan --- .../in_node_exporter_metrics/ne_thermalzone.c | 2 +- .../ne_thermalzone_linux.c | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone.c b/plugins/in_node_exporter_metrics/ne_thermalzone.c index 3b6eae2d457..9c540740c78 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone.c @@ -24,7 +24,7 @@ #include "ne.h" struct flb_ne_collector thermalzone_collector = { - .name = "thermalzone", + .name = "thermal_zone", .cb_init = NULL, .cb_update = NULL, .cb_exit = NULL diff --git a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c index aaa545ef162..f4f38479077 100644 --- a/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c +++ b/plugins/in_node_exporter_metrics/ne_thermalzone_linux.c @@ -38,7 +38,7 @@ * ---------------------------------------------------------- */ -int ne_thermalzone_init(struct flb_ne *ctx) +static int ne_thermalzone_init(struct flb_ne *ctx) { ctx->thermalzone_temp = cmt_gauge_create(ctx->cmt, "node", "thermal_zone", "temp", "Zone temperature in Celsius", @@ -69,7 +69,7 @@ int ne_thermalzone_init(struct flb_ne *ctx) return 0; } -int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) +static int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) { uint64_t tstamp; int ret; @@ -154,7 +154,7 @@ int ne_thermalzone_update_thermal_zones(struct flb_ne *ctx) return 0; } -int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) +static int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) { uint64_t tstamp; int ret; @@ -246,3 +246,22 @@ int ne_thermalzone_update_cooling_devices(struct flb_ne *ctx) return 0; } + +static int ne_thermalzone_update(struct flb_input_instance *ins, struct flb_config *config, void *in_context) +{ + int ret; + struct flb_ne *ctx = (struct flb_ne *)in_context; + + ret = ne_thermalzone_update_thermal_zones(ctx); + if (ret != 0) { + return ret; + } + return ne_thermalzone_update_cooling_devices(ctx); +} + +struct flb_ne_collector thermalzone_collector = { + .name = "thermal_zone", + .cb_init = ne_thermalzone_init, + .cb_update = ne_thermalzone_update, + .cb_exit = NULL +};