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
4748static 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+
167178struct 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+
303321static 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
892949static 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};
0 commit comments