Skip to content

in_windows_exporter_metrics: Extend metrics #10601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 18, 2025
Merged
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
2 changes: 2 additions & 0 deletions plugins/in_windows_exporter_metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(src
we_wmi.c
we_util.c
we_metric.c
we_cache.c
we_perflib.c
we_wmi_thermalzone.c
we_wmi_cpu_info.c
Expand All @@ -18,6 +19,7 @@ set(src
we_wmi_memory.c
we_wmi_paging_file.c
we_wmi_process.c
we_wmi_tcp.c
)

set(libs
Expand Down
145 changes: 137 additions & 8 deletions plugins/in_windows_exporter_metrics/we.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "we_net.h"
#include "we_logical_disk.h"
#include "we_cs.h"
#include "we_cache.h"

/* wmi collectors */
#include "we_wmi_cpu_info.h"
Expand All @@ -44,6 +45,7 @@
#include "we_wmi_memory.h"
#include "we_wmi_paging_file.h"
#include "we_wmi_process.h"
#include "we_wmi_tcp.h"

static int we_timer_cpu_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
Expand Down Expand Up @@ -95,6 +97,16 @@ static int we_timer_cs_metrics_cb(struct flb_input_instance *ins,
return 0;
}

static int we_timer_cache_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
struct flb_ne *ctx = in_context;

we_cache_update(ctx);

return 0;
}

static int we_timer_wmi_thermalzone_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
Expand Down Expand Up @@ -175,6 +187,16 @@ static int we_timer_wmi_process_metrics_cb(struct flb_input_instance *ins,
return 0;
}

static int we_timer_wmi_tcp_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
struct flb_ne *ctx = in_context;

we_wmi_tcp_update(ctx);

return 0;
}

struct flb_we_callback {
char *name;
void (*func)(char *, void *, void *);
Expand Down Expand Up @@ -262,6 +284,13 @@ static void we_cs_update_cb(char *name, void *p1, void *p2)
we_cs_update(ctx);
}

static void we_cache_update_cb(char *name, void *p1, void *p2)
{
struct flb_we *ctx = p1;

we_cache_update(ctx);
}

static void we_wmi_thermalzone_update_cb(char *name, void *p1, void *p2)
{
struct flb_we *ctx = p1;
Expand Down Expand Up @@ -318,6 +347,13 @@ static void we_wmi_process_update_cb(char *name, void *p1, void *p2)
we_wmi_process_update(ctx);
}

static void we_wmi_tcp_update_cb(char *name, void *p1, void *p2)
{
struct flb_we *ctx = p1;

we_wmi_tcp_update(ctx);
}

static int we_update_cb(struct flb_we *ctx, char *name)
{
int ret;
Expand All @@ -337,13 +373,15 @@ struct flb_we_callback ne_callbacks[] = {
{ "net", we_net_update_cb },
{ "logical_disk", we_logical_disk_update_cb },
{ "cs", we_cs_update_cb },
{ "cache", we_cache_update_cb },
{ "thermalzone", we_wmi_thermalzone_update_cb },
{ "logon", we_wmi_logon_update_cb },
{ "system", we_wmi_system_update_cb },
{ "service", we_wmi_service_update_cb },
{ "memory", we_wmi_memory_update_cb },
{ "paging_file", we_wmi_paging_file_update_cb },
{ "process", we_wmi_process_update_cb },
{ "tcp", we_wmi_tcp_update_cb },
{ 0 }
};

Expand Down Expand Up @@ -373,6 +411,7 @@ static int in_we_init(struct flb_input_instance *in,
ctx->coll_logical_disk_fd = -1;
ctx->coll_cs_fd = -1;
ctx->coll_os_fd = -1;
ctx->coll_cache_fd = -1;
ctx->coll_wmi_thermalzone_fd = -1;
ctx->coll_wmi_cpu_info_fd = -1;
ctx->coll_wmi_logon_fd = -1;
Expand All @@ -381,6 +420,7 @@ static int in_we_init(struct flb_input_instance *in,
ctx->coll_wmi_memory_fd = -1;
ctx->coll_wmi_paging_file_fd = -1;
ctx->coll_wmi_process_fd = -1;
ctx->coll_wmi_tcp_fd = -1;

ctx->callback = flb_callback_create(in->name);
if (!ctx->callback) {
Expand Down Expand Up @@ -586,10 +626,35 @@ static int in_we_init(struct flb_input_instance *in,
return -1;
}
}
else if (strncmp(entry->str, "cache", 5) == 0) {
if (ctx->cache_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 6;
}
else {
/* Create the cache collector */
ret = flb_input_set_collector_time(in,
we_timer_cache_metrics_cb,
ctx->cache_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set cache collector for Windows Exporter Metrics plugin");
return -1;
}
ctx->coll_cache_fd = ret;
}

/* Initialize cache metric collectors */
ret = we_cache_init(ctx);
if (ret) {
return -1;
}
}
else if (strncmp(entry->str, "thermalzone", 11) == 0) {
if (ctx->wmi_thermalzone_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 6;
metric_idx = 7;
}
else {
/* Create the thermalzone collector */
Expand All @@ -614,7 +679,7 @@ static int in_we_init(struct flb_input_instance *in,
else if (strncmp(entry->str, "logon", 5) == 0) {
if (ctx->wmi_logon_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 7;
metric_idx = 8;
}
else {
/* Create the logon collector */
Expand All @@ -639,7 +704,7 @@ static int in_we_init(struct flb_input_instance *in,
else if (strncmp(entry->str, "system", 6) == 0) {
if (ctx->wmi_logon_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 8;
metric_idx = 9;
}
else {
/* Create the logon collector */
Expand All @@ -664,7 +729,7 @@ static int in_we_init(struct flb_input_instance *in,
else if (strncmp(entry->str, "service", 7) == 0) {
if (ctx->wmi_service_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 9;
metric_idx = 10;
}
else {
/* Create the service collector */
Expand All @@ -689,7 +754,7 @@ static int in_we_init(struct flb_input_instance *in,
else if (strncmp(entry->str, "memory", 6) == 0) {
if (ctx->wmi_memory_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 10;
metric_idx = 11;
}
else {
/* Create the memory collector */
Expand All @@ -714,7 +779,7 @@ static int in_we_init(struct flb_input_instance *in,
else if (strncmp(entry->str, "paging_file", 11) == 0) {
if (ctx->wmi_paging_file_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 11;
metric_idx = 12;
}
else {
/* Create the paging_file collector */
Expand All @@ -739,7 +804,7 @@ static int in_we_init(struct flb_input_instance *in,
else if (strncmp(entry->str, "process", 7) == 0) {
if (ctx->wmi_process_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 12;
metric_idx = 13;
}
else {
/* Create the process collector */
Expand All @@ -761,6 +826,31 @@ static int in_we_init(struct flb_input_instance *in,
return -1;
}
}
else if (strncmp(entry->str, "tcp", 3) == 0) {
if (ctx->wmi_tcp_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 14;
}
else {
/* Create the process collector */
ret = flb_input_set_collector_time(in,
we_timer_wmi_tcp_metrics_cb,
ctx->wmi_tcp_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set tcp collector for Windows Exporter Metrics plugin");
return -1;
}
ctx->coll_wmi_tcp_fd = ret;
}

/* Initialize tcp metric collectors */
ret = we_wmi_tcp_init(ctx);
if (ret) {
return -1;
}
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
metric_idx = -1;
Expand Down Expand Up @@ -822,6 +912,9 @@ static int in_we_exit(void *data, struct flb_config *config)
else if (strncmp(entry->str, "cs", 2) == 0) {
we_cs_exit(ctx);
}
else if (strncmp(entry->str, "cache", 5) == 0) {
we_cache_exit(ctx);
}
else if (strncmp(entry->str, "thermalzone", 11) == 0) {
we_wmi_thermalzone_exit(ctx);
}
Expand All @@ -843,6 +936,9 @@ static int in_we_exit(void *data, struct flb_config *config)
else if (strncmp(entry->str, "process", 7) == 0) {
we_wmi_process_exit(ctx);
}
else if (strncmp(entry->str, "tcp", 3) == 0) {
we_wmi_tcp_exit(ctx);
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
}
Expand All @@ -868,6 +964,9 @@ static int in_we_exit(void *data, struct flb_config *config)
if (ctx->coll_os_fd != -1) {
we_os_exit(ctx);
}
if (ctx->coll_cache_fd != -1) {
we_cache_exit(ctx);
}
if (ctx->coll_wmi_thermalzone_fd != -1) {
we_wmi_thermalzone_exit(ctx);
}
Expand All @@ -892,6 +991,9 @@ static int in_we_exit(void *data, struct flb_config *config)
if (ctx->coll_wmi_process_fd != -1) {
we_wmi_process_exit(ctx);
}
if (ctx->coll_wmi_tcp_fd != -1) {
we_wmi_tcp_exit(ctx);
}

flb_we_config_destroy(ctx);

Expand Down Expand Up @@ -920,6 +1022,9 @@ static void in_we_pause(void *data, struct flb_config *config)
if (ctx->coll_os_fd != -1) {
flb_input_collector_pause(ctx->coll_os_fd, ctx->ins);
}
if (ctx->coll_cache_fd != -1) {
flb_input_collector_pause(ctx->coll_cache_fd, ctx->ins);
}
if (ctx->coll_wmi_thermalzone_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_thermalzone_fd, ctx->ins);
}
Expand All @@ -944,6 +1049,9 @@ static void in_we_pause(void *data, struct flb_config *config)
if (ctx->coll_wmi_process_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_process_fd, ctx->ins);
}
if (ctx->coll_wmi_tcp_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_tcp_fd, ctx->ins);
}
}

static void in_we_resume(void *data, struct flb_config *config)
Expand Down Expand Up @@ -971,6 +1079,9 @@ static void in_we_resume(void *data, struct flb_config *config)
if (ctx->coll_os_fd != -1) {
flb_input_collector_resume(ctx->coll_os_fd, ctx->ins);
}
if (ctx->coll_cache_fd != -1) {
flb_input_collector_resume(ctx->coll_cache_fd, ctx->ins);
}
if (ctx->coll_wmi_thermalzone_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_thermalzone_fd, ctx->ins);
}
Expand All @@ -992,6 +1103,12 @@ static void in_we_resume(void *data, struct flb_config *config)
if (ctx->coll_wmi_paging_file_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_paging_file_fd, ctx->ins);
}
if (ctx->coll_wmi_process_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_process_fd, ctx->ins);
}
if (ctx->coll_wmi_tcp_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_tcp_fd, ctx->ins);
}
}

/* Configuration properties map */
Expand Down Expand Up @@ -1035,6 +1152,12 @@ static struct flb_config_map config_map[] = {
"scrape interval to collect os metrics from the node."
},

{
FLB_CONFIG_MAP_TIME, "collector.cache.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_we, cache_scrape_interval),
"scrape interval to collect cache metrics from the node."
},

{
FLB_CONFIG_MAP_TIME, "collector.thermalzone.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_we, wmi_thermalzone_scrape_interval),
Expand Down Expand Up @@ -1080,9 +1203,15 @@ static struct flb_config_map config_map[] = {
"scrape interval to collect process metrics from the node."
},

{
FLB_CONFIG_MAP_TIME, "collector.tcp.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_we, wmi_tcp_scrape_interval),
"scrape interval to collect tcp metrics from the node."
},

{
FLB_CONFIG_MAP_CLIST, "metrics",
"cpu,cpu_info,os,net,logical_disk,cs,thermalzone,logon,system,service",
"cpu,cpu_info,os,net,logical_disk,cs,cache,thermalzone,logon,system,service,tcp",
0, FLB_TRUE, offsetof(struct flb_we, metrics),
"Comma separated list of keys to enable metrics."
},
Expand Down
Loading
Loading