Skip to content

Commit

Permalink
in_windows_exporter_metrics: Implement WMI based memory and paging_fi…
Browse files Browse the repository at this point in the history
…le metrics (#7817)


---------

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored Aug 19, 2023
1 parent 4fab746 commit 4cf56eb
Show file tree
Hide file tree
Showing 7 changed files with 948 additions and 0 deletions.
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 @@ -15,6 +15,8 @@ set(src
we_wmi_logon.c
we_wmi_system.c
we_wmi_service.c
we_wmi_memory.c
we_wmi_paging_file.c
)

set(libs
Expand Down
124 changes: 124 additions & 0 deletions plugins/in_windows_exporter_metrics/we.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "we_wmi_system.h"
#include "we_wmi_thermalzone.h"
#include "we_wmi_service.h"
#include "we_wmi_memory.h"
#include "we_wmi_paging_file.h"

static int we_timer_cpu_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
Expand Down Expand Up @@ -142,6 +144,26 @@ static int we_timer_wmi_service_metrics_cb(struct flb_input_instance *ins,
return 0;
}

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

we_wmi_memory_update(ctx);

return 0;
}

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

we_wmi_paging_file_update(ctx);

return 0;
}

struct flb_we_callback {
char *name;
void (*func)(char *, void *, void *);
Expand Down Expand Up @@ -264,6 +286,20 @@ static void we_wmi_service_update_cb(char *name, void *p1, void *p2)
we_wmi_service_update(ctx);
}

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

we_wmi_memory_update(ctx);
}

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

we_wmi_paging_file_update(ctx);
}

static int we_update_cb(struct flb_we *ctx, char *name)
{
int ret;
Expand All @@ -287,6 +323,8 @@ struct flb_we_callback ne_callbacks[] = {
{ "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 },
{ 0 }
};

Expand Down Expand Up @@ -321,6 +359,8 @@ static int in_we_init(struct flb_input_instance *in,
ctx->coll_wmi_logon_fd = -1;
ctx->coll_wmi_system_fd = -1;
ctx->coll_wmi_service_fd = -1;
ctx->coll_wmi_memory_fd = -1;
ctx->coll_wmi_paging_file_fd = -1;

ctx->callback = flb_callback_create(in->name);
if (!ctx->callback) {
Expand Down Expand Up @@ -625,6 +665,54 @@ static int in_we_init(struct flb_input_instance *in,
return -1;
}
}
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;
} else {
/* Create the memory collector */
ret = flb_input_set_collector_time(in,
we_timer_wmi_memory_metrics_cb,
ctx->wmi_memory_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set memory collector for Windows Exporter Metrics plugin");
return -1;
}
ctx->coll_wmi_memory_fd = ret;
}

/* Initialize memory metric collectors */
ret = we_wmi_memory_init(ctx);
if (ret) {
return -1;
}
}
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;
} else {
/* Create the paging_file collector */
ret = flb_input_set_collector_time(in,
we_timer_wmi_paging_file_metrics_cb,
ctx->wmi_paging_file_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set paging_file collector for Windows Exporter Metrics plugin");
return -1;
}
ctx->coll_wmi_paging_file_fd = ret;
}

/* Initialize paging_file metric collectors */
ret = we_wmi_paging_file_init(ctx);
if (ret) {
return -1;
}
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
metric_idx = -1;
Expand Down Expand Up @@ -698,6 +786,12 @@ static int in_we_exit(void *data, struct flb_config *config)
else if (strncmp(entry->str, "service", 7) == 0) {
we_wmi_service_exit(ctx);
}
else if (strncmp(entry->str, "memory", 6) == 0) {
we_wmi_memory_exit(ctx);
}
else if (strncmp(entry->str, "paging_file", 11) == 0) {
we_wmi_paging_file_exit(ctx);
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
}
Expand Down Expand Up @@ -738,6 +832,12 @@ static int in_we_exit(void *data, struct flb_config *config)
if (ctx->coll_wmi_service_fd != -1) {
we_wmi_service_exit(ctx);
}
if (ctx->coll_wmi_memory_fd != -1) {
we_wmi_memory_exit(ctx);
}
if (ctx->coll_wmi_paging_file_fd != -1) {
we_wmi_paging_file_exit(ctx);
}

flb_we_config_destroy(ctx);

Expand Down Expand Up @@ -781,6 +881,12 @@ static void in_we_pause(void *data, struct flb_config *config)
if (ctx->coll_wmi_service_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_service_fd, ctx->ins);
}
if (ctx->coll_wmi_memory_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_memory_fd, ctx->ins);
}
if (ctx->coll_wmi_paging_file_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_paging_file_fd, ctx->ins);
}
}

static void in_we_resume(void *data, struct flb_config *config)
Expand Down Expand Up @@ -820,6 +926,12 @@ static void in_we_resume(void *data, struct flb_config *config)
if (ctx->coll_wmi_service_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_service_fd, ctx->ins);
}
if (ctx->coll_wmi_memory_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_memory_fd, ctx->ins);
}
if (ctx->coll_wmi_paging_file_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_paging_file_fd, ctx->ins);
}
}

/* Configuration properties map */
Expand Down Expand Up @@ -890,6 +1002,18 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_we, wmi_service_scrape_interval),
"scrape interval to collect service metrics from the node."
},

{
FLB_CONFIG_MAP_TIME, "collector.memory.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_we, wmi_memory_scrape_interval),
"scrape interval to collect memory metrics from the node."
},
{
FLB_CONFIG_MAP_TIME, "collector.paging_file.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_we, wmi_paging_file_scrape_interval),
"scrape interval to collect paging_file metrics from the node."
},

{
FLB_CONFIG_MAP_CLIST, "metrics",
"cpu,cpu_info,os,net,logical_disk,cs,thermalzone,logon,system,service",
Expand Down
51 changes: 51 additions & 0 deletions plugins/in_windows_exporter_metrics/we.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,51 @@ struct we_wmi_service_counters {
int operational;
};

struct we_wmi_memory_counters {
struct wmi_query_spec *info;
struct cmt_gauge *available_bytes;
struct cmt_gauge *cache_bytes;
struct cmt_gauge *cache_bytes_peak;
struct cmt_gauge *cache_faults_total;
struct cmt_gauge *commit_limit;
struct cmt_gauge *committed_bytes;
struct cmt_gauge *demand_zero_faults_total;
struct cmt_gauge *free_and_zero_page_list_bytes;
struct cmt_gauge *free_system_page_table_entries;
struct cmt_gauge *modified_page_list_bytes;
struct cmt_gauge *page_faults_total;
struct cmt_gauge *swap_page_reads_total;
struct cmt_gauge *swap_pages_read_total;
struct cmt_gauge *swap_pages_written_total;
struct cmt_gauge *swap_page_operations_total;
struct cmt_gauge *swap_page_writes_total;
struct cmt_gauge *pool_nonpaged_allocs_total;
struct cmt_gauge *pool_nonpaged_bytes;
struct cmt_gauge *pool_paged_allocs_total;
struct cmt_gauge *pool_paged_bytes;
struct cmt_gauge *pool_paged_resident_bytes;
struct cmt_gauge *standby_cache_core_bytes;
struct cmt_gauge *standby_cache_normal_priority_bytes;
struct cmt_gauge *standby_cache_reserve_bytes;
struct cmt_gauge *system_cache_resident_bytes;
struct cmt_gauge *system_code_resident_bytes;
struct cmt_gauge *system_code_total_bytes;
struct cmt_gauge *system_driver_resident_bytes;
struct cmt_gauge *system_driver_total_bytes;
struct cmt_gauge *transition_faults_total;
struct cmt_gauge *transition_pages_repurposed_total;
struct cmt_gauge *write_copies_total;
int operational;
};

struct we_wmi_paging_file_counters {
struct wmi_query_spec *info;
struct cmt_gauge *allocated_base_size_megabytes;
struct cmt_gauge *current_usage_megabytes;
struct cmt_gauge *peak_usage_megabytes;
int operational;
};

struct we_os_counters {
struct cmt_gauge *info;
struct cmt_gauge *users;
Expand Down Expand Up @@ -220,6 +265,8 @@ struct flb_we {
int wmi_logon_scrape_interval;
int wmi_system_scrape_interval;
int wmi_service_scrape_interval;
int wmi_memory_scrape_interval;
int wmi_paging_file_scrape_interval;

int coll_cpu_fd; /* collector fd (cpu) */
int coll_net_fd; /* collector fd (net) */
Expand All @@ -231,6 +278,8 @@ struct flb_we {
int coll_wmi_logon_fd; /* collector fd (wmi_logon) */
int coll_wmi_system_fd; /* collector fd (wmi_system) */
int coll_wmi_service_fd; /* collector fd (wmi_service) */
int coll_wmi_memory_fd; /* collector fd (wmi_memory) */
int coll_wmi_paging_file_fd; /* collector fd (wmi_paging_file) */

/*
* Metrics Contexts
Expand All @@ -247,6 +296,8 @@ struct flb_we {
struct we_wmi_logon_counters *wmi_logon;
struct we_wmi_system_counters *wmi_system;
struct we_wmi_service_counters *wmi_service;
struct we_wmi_memory_counters *wmi_memory;
struct we_wmi_paging_file_counters *wmi_paging_file;
};

typedef int (*collector_cb)(struct flb_we *);
Expand Down
Loading

0 comments on commit 4cf56eb

Please sign in to comment.