|
35 | 35 | #include "we_logical_disk.h" |
36 | 36 | #include "we_cs.h" |
37 | 37 | #include "we_cache.h" |
| 38 | +#include "we_performancecounter.h" |
38 | 39 |
|
39 | 40 | /* wmi collectors */ |
40 | 41 | #include "we_wmi_cpu_info.h" |
@@ -197,6 +198,17 @@ static int we_timer_wmi_tcp_metrics_cb(struct flb_input_instance *ins, |
197 | 198 | return 0; |
198 | 199 | } |
199 | 200 |
|
| 201 | +static int we_timer_performancecounter_metrics_cb(struct flb_input_instance *ins, |
| 202 | + struct flb_config *config, |
| 203 | + void *in_context) |
| 204 | +{ |
| 205 | + struct flb_we *ctx = in_context; |
| 206 | + |
| 207 | + we_performancecounter_update(ctx); |
| 208 | + |
| 209 | + return 0; |
| 210 | +} |
| 211 | + |
200 | 212 | struct flb_we_callback { |
201 | 213 | char *name; |
202 | 214 | void (*func)(char *, void *, void *); |
@@ -354,6 +366,13 @@ static void we_wmi_tcp_update_cb(char *name, void *p1, void *p2) |
354 | 366 | we_wmi_tcp_update(ctx); |
355 | 367 | } |
356 | 368 |
|
| 369 | +static void we_performancecounter_update_cb(char *name, void *p1, void *p2) |
| 370 | +{ |
| 371 | + struct flb_we *ctx = p1; |
| 372 | + |
| 373 | + we_performancecounter_update(ctx); |
| 374 | +} |
| 375 | + |
357 | 376 | static int we_update_cb(struct flb_we *ctx, char *name) |
358 | 377 | { |
359 | 378 | int ret; |
@@ -382,6 +401,7 @@ struct flb_we_callback ne_callbacks[] = { |
382 | 401 | { "paging_file", we_wmi_paging_file_update_cb }, |
383 | 402 | { "process", we_wmi_process_update_cb }, |
384 | 403 | { "tcp", we_wmi_tcp_update_cb }, |
| 404 | + { "performancecounter", we_performancecounter_update_cb }, |
385 | 405 | { 0 } |
386 | 406 | }; |
387 | 407 |
|
@@ -421,6 +441,7 @@ static int in_we_init(struct flb_input_instance *in, |
421 | 441 | ctx->coll_wmi_paging_file_fd = -1; |
422 | 442 | ctx->coll_wmi_process_fd = -1; |
423 | 443 | ctx->coll_wmi_tcp_fd = -1; |
| 444 | + ctx->coll_performancecounter_fd = -1; |
424 | 445 |
|
425 | 446 | ctx->callback = flb_callback_create(in->name); |
426 | 447 | if (!ctx->callback) { |
@@ -474,6 +495,7 @@ static int in_we_init(struct flb_input_instance *in, |
474 | 495 | if (ctx->metrics) { |
475 | 496 | mk_list_foreach(head, ctx->metrics) { |
476 | 497 | entry = mk_list_entry(head, struct flb_slist_entry, _head); |
| 498 | + metric_idx = -1; |
477 | 499 | ret = flb_callback_exists(ctx->callback, entry->str); |
478 | 500 |
|
479 | 501 | if (ret == FLB_FALSE) { |
@@ -851,6 +873,32 @@ static int in_we_init(struct flb_input_instance *in, |
851 | 873 | return -1; |
852 | 874 | } |
853 | 875 | } |
| 876 | + else if (strncmp(entry->str, "performancecounter", 18) == 0) { |
| 877 | + if (ctx->performancecounter_scrape_interval == 0) { |
| 878 | + flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str); |
| 879 | + metric_idx = 15; |
| 880 | + } |
| 881 | + else { |
| 882 | + /* Create the performancecounter collector */ |
| 883 | + ret = flb_input_set_collector_time( |
| 884 | + in, |
| 885 | + we_timer_performancecounter_metrics_cb, |
| 886 | + ctx->performancecounter_scrape_interval, 0, |
| 887 | + config); |
| 888 | + if (ret == -1) { |
| 889 | + flb_plg_error(ctx->ins, |
| 890 | + "could not set performancecounter collector " |
| 891 | + "for Windows Exporter Metrics plugin"); |
| 892 | + return -1; |
| 893 | + } |
| 894 | + ctx->coll_performancecounter_fd = ret; |
| 895 | + } |
| 896 | + |
| 897 | + ret = we_performancecounter_init(ctx); |
| 898 | + if (ret) { |
| 899 | + return -1; |
| 900 | + } |
| 901 | + } |
854 | 902 | else { |
855 | 903 | flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str); |
856 | 904 | metric_idx = -1; |
@@ -939,6 +987,9 @@ static int in_we_exit(void *data, struct flb_config *config) |
939 | 987 | else if (strncmp(entry->str, "tcp", 3) == 0) { |
940 | 988 | we_wmi_tcp_exit(ctx); |
941 | 989 | } |
| 990 | + else if (strncmp(entry->str, "performancecounter", 18) == 0) { |
| 991 | + we_performancecounter_exit(ctx); |
| 992 | + } |
942 | 993 | else { |
943 | 994 | flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str); |
944 | 995 | } |
@@ -994,6 +1045,9 @@ static int in_we_exit(void *data, struct flb_config *config) |
994 | 1045 | if (ctx->coll_wmi_tcp_fd != -1) { |
995 | 1046 | we_wmi_tcp_exit(ctx); |
996 | 1047 | } |
| 1048 | + if (ctx->coll_performancecounter_fd != -1) { |
| 1049 | + we_performancecounter_exit(ctx); |
| 1050 | + } |
997 | 1051 |
|
998 | 1052 | flb_we_config_destroy(ctx); |
999 | 1053 |
|
@@ -1052,6 +1106,9 @@ static void in_we_pause(void *data, struct flb_config *config) |
1052 | 1106 | if (ctx->coll_wmi_tcp_fd != -1) { |
1053 | 1107 | flb_input_collector_pause(ctx->coll_wmi_tcp_fd, ctx->ins); |
1054 | 1108 | } |
| 1109 | + if (ctx->coll_performancecounter_fd != -1) { |
| 1110 | + flb_input_collector_pause(ctx->coll_performancecounter_fd, ctx->ins); |
| 1111 | + } |
1055 | 1112 | } |
1056 | 1113 |
|
1057 | 1114 | static void in_we_resume(void *data, struct flb_config *config) |
@@ -1109,6 +1166,9 @@ static void in_we_resume(void *data, struct flb_config *config) |
1109 | 1166 | if (ctx->coll_wmi_tcp_fd != -1) { |
1110 | 1167 | flb_input_collector_resume(ctx->coll_wmi_tcp_fd, ctx->ins); |
1111 | 1168 | } |
| 1169 | + if (ctx->coll_performancecounter_fd != -1) { |
| 1170 | + flb_input_collector_resume(ctx->coll_performancecounter_fd, ctx->ins); |
| 1171 | + } |
1112 | 1172 | } |
1113 | 1173 |
|
1114 | 1174 | /* Configuration properties map */ |
@@ -1209,6 +1269,12 @@ static struct flb_config_map config_map[] = { |
1209 | 1269 | "scrape interval to collect tcp metrics from the node." |
1210 | 1270 | }, |
1211 | 1271 |
|
| 1272 | + { |
| 1273 | + FLB_CONFIG_MAP_TIME, "collector.performancecounter.scrape_interval", "0", |
| 1274 | + 0, FLB_TRUE, offsetof(struct flb_we, performancecounter_scrape_interval), |
| 1275 | + "scrape interval to collect performancecounter metrics from the node." |
| 1276 | + }, |
| 1277 | + |
1212 | 1278 | { |
1213 | 1279 | FLB_CONFIG_MAP_CLIST, "metrics", |
1214 | 1280 | "cpu,cpu_info,os,net,logical_disk,cs,cache,thermalzone,logon,system,service,tcp", |
@@ -1255,6 +1321,11 @@ static struct flb_config_map config_map[] = { |
1255 | 1321 | 0, FLB_TRUE, offsetof(struct flb_we, raw_denying_process), |
1256 | 1322 | "Specify the regex for process metrics to prevent collection of/ignore." |
1257 | 1323 | }, |
| 1324 | + { |
| 1325 | + FLB_CONFIG_MAP_STR, "PerformanceCounter", NULL, |
| 1326 | + FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_we, raw_performance_counters), |
| 1327 | + "Windows Performance Counter in name=counter_path form." |
| 1328 | + }, |
1258 | 1329 | /* EOF */ |
1259 | 1330 | {0} |
1260 | 1331 | }; |
|
0 commit comments