Skip to content
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
1 change: 1 addition & 0 deletions plugins/in_windows_exporter_metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(src
we_wmi_service.c
we_wmi_memory.c
we_wmi_paging_file.c
we_wmi_process.c
)

set(libs
Expand Down
82 changes: 79 additions & 3 deletions plugins/in_windows_exporter_metrics/we.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "we_wmi_service.h"
#include "we_wmi_memory.h"
#include "we_wmi_paging_file.h"
#include "we_wmi_process.h"

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

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

we_wmi_process_update(ctx);

return 0;
}

struct flb_we_callback {
char *name;
void (*func)(char *, void *, void *);
Expand Down Expand Up @@ -300,6 +311,13 @@ static void we_wmi_paging_file_update_cb(char *name, void *p1, void *p2)
we_wmi_paging_file_update(ctx);
}

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

we_wmi_process_update(ctx);
}

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

Expand Down Expand Up @@ -361,6 +380,7 @@ static int in_we_init(struct flb_input_instance *in,
ctx->coll_wmi_service_fd = -1;
ctx->coll_wmi_memory_fd = -1;
ctx->coll_wmi_paging_file_fd = -1;
ctx->coll_wmi_process_fd = -1;

ctx->callback = flb_callback_create(in->name);
if (!ctx->callback) {
Expand Down Expand Up @@ -545,7 +565,8 @@ static int in_we_init(struct flb_input_instance *in,
if (ctx->cs_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 5;
} else {
}
else {
/* Create the logical_disk collector */
ret = flb_input_set_collector_time(in,
we_timer_cs_metrics_cb,
Expand Down Expand Up @@ -669,7 +690,8 @@ static int in_we_init(struct flb_input_instance *in,
if (ctx->wmi_memory_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 10;
} else {
}
else {
/* Create the memory collector */
ret = flb_input_set_collector_time(in,
we_timer_wmi_memory_metrics_cb,
Expand All @@ -693,7 +715,8 @@ static int in_we_init(struct flb_input_instance *in,
if (ctx->wmi_paging_file_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 11;
} else {
}
else {
/* Create the paging_file collector */
ret = flb_input_set_collector_time(in,
we_timer_wmi_paging_file_metrics_cb,
Expand All @@ -713,6 +736,31 @@ static int in_we_init(struct flb_input_instance *in,
return -1;
}
}
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;
}
else {
/* Create the process collector */
ret = flb_input_set_collector_time(in,
we_timer_wmi_process_metrics_cb,
ctx->wmi_process_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set process collector for Windows Exporter Metrics plugin");
return -1;
}
ctx->coll_wmi_process_fd = ret;
}

/* Initialize paging_file metric collectors */
ret = we_wmi_process_init(ctx);
if (ret) {
return -1;
}
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
metric_idx = -1;
Expand Down Expand Up @@ -792,6 +840,9 @@ static int in_we_exit(void *data, struct flb_config *config)
else if (strncmp(entry->str, "paging_file", 11) == 0) {
we_wmi_paging_file_exit(ctx);
}
else if (strncmp(entry->str, "process", 7) == 0) {
we_wmi_process_exit(ctx);
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
}
Expand Down Expand Up @@ -838,6 +889,9 @@ static int in_we_exit(void *data, struct flb_config *config)
if (ctx->coll_wmi_paging_file_fd != -1) {
we_wmi_paging_file_exit(ctx);
}
if (ctx->coll_wmi_process_fd != -1) {
we_wmi_process_exit(ctx);
}

flb_we_config_destroy(ctx);

Expand Down Expand Up @@ -887,6 +941,9 @@ static void in_we_pause(void *data, struct flb_config *config)
if (ctx->coll_wmi_paging_file_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_paging_file_fd, ctx->ins);
}
if (ctx->coll_wmi_process_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_process_fd, ctx->ins);
}
}

static void in_we_resume(void *data, struct flb_config *config)
Expand All @@ -905,6 +962,9 @@ static void in_we_resume(void *data, struct flb_config *config)
if (ctx->coll_logical_disk_fd != -1) {
flb_input_collector_resume(ctx->coll_logical_disk_fd, ctx->ins);
}
if (ctx->coll_wmi_process_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_process_fd, ctx->ins);
}
if (ctx->coll_cs_fd != -1) {
flb_input_collector_resume(ctx->coll_cs_fd, ctx->ins);
}
Expand Down Expand Up @@ -1014,6 +1074,12 @@ static struct flb_config_map config_map[] = {
"scrape interval to collect paging_file metrics from the node."
},

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

{
FLB_CONFIG_MAP_CLIST, "metrics",
"cpu,cpu_info,os,net,logical_disk,cs,thermalzone,logon,system,service",
Expand Down Expand Up @@ -1050,6 +1116,16 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_we, raw_service_exclude),
"Specify the key value condition pairs for excludeing condition to construct where clause of service metrics."
},
{
FLB_CONFIG_MAP_STR, "we.process.allow_process_regex", "/.+/",
0, FLB_TRUE, offsetof(struct flb_we, raw_allowing_process),
"Specify the regex covering the process metrics to collect."
},
{
FLB_CONFIG_MAP_STR, "we.process.deny_process_regex", NULL,
0, FLB_TRUE, offsetof(struct flb_we, raw_denying_process),
"Specify the regex for process metrics to prevent collection of/ignore."
},
/* EOF */
{0}
};
Expand Down
27 changes: 27 additions & 0 deletions plugins/in_windows_exporter_metrics/we.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ struct we_wmi_paging_file_counters {
int operational;
};

struct we_wmi_process_counters {
struct wmi_query_spec *info;
struct cmt_gauge *start_time;
struct cmt_gauge *handles;
struct cmt_gauge *cpu_time_total;
struct cmt_gauge *io_bytes_total;
struct cmt_gauge *io_operations_total;
struct cmt_gauge *page_faults_total;
struct cmt_gauge *page_file_bytes;
struct cmt_gauge *pool_bytes;
struct cmt_gauge *priority_base;
struct cmt_gauge *thread_count;
struct cmt_gauge *private_bytes;
struct cmt_gauge *virtual_bytes;
struct cmt_gauge *working_set_private_bytes;
struct cmt_gauge *working_set_peak_bytes;
struct cmt_gauge *working_set_bytes;
int operational;
};

struct we_os_counters {
struct cmt_gauge *info;
struct cmt_gauge *users;
Expand Down Expand Up @@ -235,6 +255,8 @@ struct flb_we {
char *raw_where_clause;
char *raw_service_include;
char *raw_service_exclude;
char *raw_allowing_process;
char *raw_denying_process;
char *service_include_buffer;
int service_include_buffer_size;
char *service_exclude_buffer;
Expand All @@ -243,6 +265,8 @@ struct flb_we {
struct flb_regex *allowing_disk_regex;
struct flb_regex *denying_disk_regex;
struct flb_regex *allowing_nic_regex;
struct flb_regex *allowing_process_regex;
struct flb_regex *denying_process_regex;

struct we_perflib_context perflib_context;
/* WMI locator and service contexts */
Expand All @@ -267,6 +291,7 @@ struct flb_we {
int wmi_service_scrape_interval;
int wmi_memory_scrape_interval;
int wmi_paging_file_scrape_interval;
int wmi_process_scrape_interval;

int coll_cpu_fd; /* collector fd (cpu) */
int coll_net_fd; /* collector fd (net) */
Expand All @@ -280,6 +305,7 @@ struct flb_we {
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) */
int coll_wmi_process_fd; /* collector fd (wmi_process) */

/*
* Metrics Contexts
Expand All @@ -298,6 +324,7 @@ struct flb_we {
struct we_wmi_service_counters *wmi_service;
struct we_wmi_memory_counters *wmi_memory;
struct we_wmi_paging_file_counters *wmi_paging_file;
struct we_wmi_process_counters *wmi_process;
};

typedef int (*collector_cb)(struct flb_we *);
Expand Down
19 changes: 19 additions & 0 deletions plugins/in_windows_exporter_metrics/we_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct flb_we *flb_we_config_create(struct flb_input_instance *ins,
ctx->service_include_buffer_size = 0;
ctx->service_exclude_buffer = NULL;
ctx->service_exclude_buffer_size = 0;
ctx->allowing_process_regex = NULL;
ctx->denying_process_regex = NULL;

/* Load the config map */
ret = flb_input_config_map_set(ins, (void *) ctx);
Expand Down Expand Up @@ -91,6 +93,15 @@ struct flb_we *flb_we_config_create(struct flb_input_instance *ins,
}
}

/* Process allow/deny regex rules for process metrics */
if (ctx->raw_allowing_process != NULL) {
ctx->allowing_process_regex = flb_regex_create(ctx->raw_allowing_process);
}

if (ctx->raw_denying_process != NULL) {
ctx->denying_process_regex = flb_regex_create(ctx->raw_denying_process);
}

ctx->cmt = cmt_create();
if (!ctx->cmt) {
flb_plg_error(ins, "could not initialize CMetrics");
Expand Down Expand Up @@ -127,6 +138,14 @@ void flb_we_config_destroy(struct flb_we *ctx)
flb_free(ctx->service_exclude_buffer);
}

if (ctx->allowing_process_regex != NULL) {
flb_regex_destroy(ctx->allowing_process_regex);
}

if (ctx->denying_disk_regex != NULL) {
flb_regex_destroy(ctx->denying_disk_regex);
}

if (ctx->cmt) {
cmt_destroy(ctx->cmt);
}
Expand Down
Loading