Skip to content

Commit 996d569

Browse files
cosmo0920Leonardo Alminana
authored andcommitted
in_windows_exporter_metrics: Implement WMI based process metrics (#7860)
--------- Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent c9f38e1 commit 996d569

File tree

6 files changed

+572
-3
lines changed

6 files changed

+572
-3
lines changed

plugins/in_windows_exporter_metrics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(src
1717
we_wmi_service.c
1818
we_wmi_memory.c
1919
we_wmi_paging_file.c
20+
we_wmi_process.c
2021
)
2122

2223
set(libs

plugins/in_windows_exporter_metrics/we.c

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "we_wmi_service.h"
4444
#include "we_wmi_memory.h"
4545
#include "we_wmi_paging_file.h"
46+
#include "we_wmi_process.h"
4647

4748
static int we_timer_cpu_metrics_cb(struct flb_input_instance *ins,
4849
struct flb_config *config, void *in_context)
@@ -164,6 +165,16 @@ static int we_timer_wmi_paging_file_metrics_cb(struct flb_input_instance *ins,
164165
return 0;
165166
}
166167

168+
static int we_timer_wmi_process_metrics_cb(struct flb_input_instance *ins,
169+
struct flb_config *config, void *in_context)
170+
{
171+
struct flb_ne *ctx = in_context;
172+
173+
we_wmi_process_update(ctx);
174+
175+
return 0;
176+
}
177+
167178
struct flb_we_callback {
168179
char *name;
169180
void (*func)(char *, void *, void *);
@@ -300,6 +311,13 @@ static void we_wmi_paging_file_update_cb(char *name, void *p1, void *p2)
300311
we_wmi_paging_file_update(ctx);
301312
}
302313

314+
static void we_wmi_process_update_cb(char *name, void *p1, void *p2)
315+
{
316+
struct flb_we *ctx = p1;
317+
318+
we_wmi_process_update(ctx);
319+
}
320+
303321
static int we_update_cb(struct flb_we *ctx, char *name)
304322
{
305323
int ret;
@@ -325,6 +343,7 @@ struct flb_we_callback ne_callbacks[] = {
325343
{ "service", we_wmi_service_update_cb },
326344
{ "memory", we_wmi_memory_update_cb },
327345
{ "paging_file", we_wmi_paging_file_update_cb },
346+
{ "process", we_wmi_process_update_cb },
328347
{ 0 }
329348
};
330349

@@ -361,6 +380,7 @@ static int in_we_init(struct flb_input_instance *in,
361380
ctx->coll_wmi_service_fd = -1;
362381
ctx->coll_wmi_memory_fd = -1;
363382
ctx->coll_wmi_paging_file_fd = -1;
383+
ctx->coll_wmi_process_fd = -1;
364384

365385
ctx->callback = flb_callback_create(in->name);
366386
if (!ctx->callback) {
@@ -545,7 +565,8 @@ static int in_we_init(struct flb_input_instance *in,
545565
if (ctx->cs_scrape_interval == 0) {
546566
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
547567
metric_idx = 5;
548-
} else {
568+
}
569+
else {
549570
/* Create the logical_disk collector */
550571
ret = flb_input_set_collector_time(in,
551572
we_timer_cs_metrics_cb,
@@ -669,7 +690,8 @@ static int in_we_init(struct flb_input_instance *in,
669690
if (ctx->wmi_memory_scrape_interval == 0) {
670691
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
671692
metric_idx = 10;
672-
} else {
693+
}
694+
else {
673695
/* Create the memory collector */
674696
ret = flb_input_set_collector_time(in,
675697
we_timer_wmi_memory_metrics_cb,
@@ -693,7 +715,8 @@ static int in_we_init(struct flb_input_instance *in,
693715
if (ctx->wmi_paging_file_scrape_interval == 0) {
694716
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
695717
metric_idx = 11;
696-
} else {
718+
}
719+
else {
697720
/* Create the paging_file collector */
698721
ret = flb_input_set_collector_time(in,
699722
we_timer_wmi_paging_file_metrics_cb,
@@ -713,6 +736,31 @@ static int in_we_init(struct flb_input_instance *in,
713736
return -1;
714737
}
715738
}
739+
else if (strncmp(entry->str, "process", 7) == 0) {
740+
if (ctx->wmi_process_scrape_interval == 0) {
741+
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
742+
metric_idx = 12;
743+
}
744+
else {
745+
/* Create the process collector */
746+
ret = flb_input_set_collector_time(in,
747+
we_timer_wmi_process_metrics_cb,
748+
ctx->wmi_process_scrape_interval, 0,
749+
config);
750+
if (ret == -1) {
751+
flb_plg_error(ctx->ins,
752+
"could not set process collector for Windows Exporter Metrics plugin");
753+
return -1;
754+
}
755+
ctx->coll_wmi_process_fd = ret;
756+
}
757+
758+
/* Initialize paging_file metric collectors */
759+
ret = we_wmi_process_init(ctx);
760+
if (ret) {
761+
return -1;
762+
}
763+
}
716764
else {
717765
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
718766
metric_idx = -1;
@@ -792,6 +840,9 @@ static int in_we_exit(void *data, struct flb_config *config)
792840
else if (strncmp(entry->str, "paging_file", 11) == 0) {
793841
we_wmi_paging_file_exit(ctx);
794842
}
843+
else if (strncmp(entry->str, "process", 7) == 0) {
844+
we_wmi_process_exit(ctx);
845+
}
795846
else {
796847
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
797848
}
@@ -838,6 +889,9 @@ static int in_we_exit(void *data, struct flb_config *config)
838889
if (ctx->coll_wmi_paging_file_fd != -1) {
839890
we_wmi_paging_file_exit(ctx);
840891
}
892+
if (ctx->coll_wmi_process_fd != -1) {
893+
we_wmi_process_exit(ctx);
894+
}
841895

842896
flb_we_config_destroy(ctx);
843897

@@ -887,6 +941,9 @@ static void in_we_pause(void *data, struct flb_config *config)
887941
if (ctx->coll_wmi_paging_file_fd != -1) {
888942
flb_input_collector_pause(ctx->coll_wmi_paging_file_fd, ctx->ins);
889943
}
944+
if (ctx->coll_wmi_process_fd != -1) {
945+
flb_input_collector_pause(ctx->coll_wmi_process_fd, ctx->ins);
946+
}
890947
}
891948

892949
static void in_we_resume(void *data, struct flb_config *config)
@@ -905,6 +962,9 @@ static void in_we_resume(void *data, struct flb_config *config)
905962
if (ctx->coll_logical_disk_fd != -1) {
906963
flb_input_collector_resume(ctx->coll_logical_disk_fd, ctx->ins);
907964
}
965+
if (ctx->coll_wmi_process_fd != -1) {
966+
flb_input_collector_resume(ctx->coll_wmi_process_fd, ctx->ins);
967+
}
908968
if (ctx->coll_cs_fd != -1) {
909969
flb_input_collector_resume(ctx->coll_cs_fd, ctx->ins);
910970
}
@@ -1014,6 +1074,12 @@ static struct flb_config_map config_map[] = {
10141074
"scrape interval to collect paging_file metrics from the node."
10151075
},
10161076

1077+
{
1078+
FLB_CONFIG_MAP_TIME, "collector.process.scrape_interval", "0",
1079+
0, FLB_TRUE, offsetof(struct flb_we, wmi_process_scrape_interval),
1080+
"scrape interval to collect process metrics from the node."
1081+
},
1082+
10171083
{
10181084
FLB_CONFIG_MAP_CLIST, "metrics",
10191085
"cpu,cpu_info,os,net,logical_disk,cs,thermalzone,logon,system,service",
@@ -1050,6 +1116,16 @@ static struct flb_config_map config_map[] = {
10501116
0, FLB_TRUE, offsetof(struct flb_we, raw_service_exclude),
10511117
"Specify the key value condition pairs for excludeing condition to construct where clause of service metrics."
10521118
},
1119+
{
1120+
FLB_CONFIG_MAP_STR, "we.process.allow_process_regex", "/.+/",
1121+
0, FLB_TRUE, offsetof(struct flb_we, raw_allowing_process),
1122+
"Specify the regex covering the process metrics to collect."
1123+
},
1124+
{
1125+
FLB_CONFIG_MAP_STR, "we.process.deny_process_regex", NULL,
1126+
0, FLB_TRUE, offsetof(struct flb_we, raw_denying_process),
1127+
"Specify the regex for process metrics to prevent collection of/ignore."
1128+
},
10531129
/* EOF */
10541130
{0}
10551131
};

plugins/in_windows_exporter_metrics/we.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,26 @@ struct we_wmi_paging_file_counters {
199199
int operational;
200200
};
201201

202+
struct we_wmi_process_counters {
203+
struct wmi_query_spec *info;
204+
struct cmt_gauge *start_time;
205+
struct cmt_gauge *handles;
206+
struct cmt_gauge *cpu_time_total;
207+
struct cmt_gauge *io_bytes_total;
208+
struct cmt_gauge *io_operations_total;
209+
struct cmt_gauge *page_faults_total;
210+
struct cmt_gauge *page_file_bytes;
211+
struct cmt_gauge *pool_bytes;
212+
struct cmt_gauge *priority_base;
213+
struct cmt_gauge *thread_count;
214+
struct cmt_gauge *private_bytes;
215+
struct cmt_gauge *virtual_bytes;
216+
struct cmt_gauge *working_set_private_bytes;
217+
struct cmt_gauge *working_set_peak_bytes;
218+
struct cmt_gauge *working_set_bytes;
219+
int operational;
220+
};
221+
202222
struct we_os_counters {
203223
struct cmt_gauge *info;
204224
struct cmt_gauge *users;
@@ -235,6 +255,8 @@ struct flb_we {
235255
char *raw_where_clause;
236256
char *raw_service_include;
237257
char *raw_service_exclude;
258+
char *raw_allowing_process;
259+
char *raw_denying_process;
238260
char *service_include_buffer;
239261
int service_include_buffer_size;
240262
char *service_exclude_buffer;
@@ -243,6 +265,8 @@ struct flb_we {
243265
struct flb_regex *allowing_disk_regex;
244266
struct flb_regex *denying_disk_regex;
245267
struct flb_regex *allowing_nic_regex;
268+
struct flb_regex *allowing_process_regex;
269+
struct flb_regex *denying_process_regex;
246270

247271
struct we_perflib_context perflib_context;
248272
/* WMI locator and service contexts */
@@ -267,6 +291,7 @@ struct flb_we {
267291
int wmi_service_scrape_interval;
268292
int wmi_memory_scrape_interval;
269293
int wmi_paging_file_scrape_interval;
294+
int wmi_process_scrape_interval;
270295

271296
int coll_cpu_fd; /* collector fd (cpu) */
272297
int coll_net_fd; /* collector fd (net) */
@@ -280,6 +305,7 @@ struct flb_we {
280305
int coll_wmi_service_fd; /* collector fd (wmi_service) */
281306
int coll_wmi_memory_fd; /* collector fd (wmi_memory) */
282307
int coll_wmi_paging_file_fd; /* collector fd (wmi_paging_file) */
308+
int coll_wmi_process_fd; /* collector fd (wmi_process) */
283309

284310
/*
285311
* Metrics Contexts
@@ -298,6 +324,7 @@ struct flb_we {
298324
struct we_wmi_service_counters *wmi_service;
299325
struct we_wmi_memory_counters *wmi_memory;
300326
struct we_wmi_paging_file_counters *wmi_paging_file;
327+
struct we_wmi_process_counters *wmi_process;
301328
};
302329

303330
typedef int (*collector_cb)(struct flb_we *);

plugins/in_windows_exporter_metrics/we_config.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ struct flb_we *flb_we_config_create(struct flb_input_instance *ins,
4242
ctx->service_include_buffer_size = 0;
4343
ctx->service_exclude_buffer = NULL;
4444
ctx->service_exclude_buffer_size = 0;
45+
ctx->allowing_process_regex = NULL;
46+
ctx->denying_process_regex = NULL;
4547

4648
/* Load the config map */
4749
ret = flb_input_config_map_set(ins, (void *) ctx);
@@ -91,6 +93,15 @@ struct flb_we *flb_we_config_create(struct flb_input_instance *ins,
9193
}
9294
}
9395

96+
/* Process allow/deny regex rules for process metrics */
97+
if (ctx->raw_allowing_process != NULL) {
98+
ctx->allowing_process_regex = flb_regex_create(ctx->raw_allowing_process);
99+
}
100+
101+
if (ctx->raw_denying_process != NULL) {
102+
ctx->denying_process_regex = flb_regex_create(ctx->raw_denying_process);
103+
}
104+
94105
ctx->cmt = cmt_create();
95106
if (!ctx->cmt) {
96107
flb_plg_error(ins, "could not initialize CMetrics");
@@ -127,6 +138,14 @@ void flb_we_config_destroy(struct flb_we *ctx)
127138
flb_free(ctx->service_exclude_buffer);
128139
}
129140

141+
if (ctx->allowing_process_regex != NULL) {
142+
flb_regex_destroy(ctx->allowing_process_regex);
143+
}
144+
145+
if (ctx->denying_disk_regex != NULL) {
146+
flb_regex_destroy(ctx->denying_disk_regex);
147+
}
148+
130149
if (ctx->cmt) {
131150
cmt_destroy(ctx->cmt);
132151
}

0 commit comments

Comments
 (0)