3535#include "we_logical_disk.h"
3636#include "we_cs.h"
3737
38+ /* wmi collectors */
39+ #include "we_wmi_cpu_info.h"
40+ #include "we_wmi_logon.h"
41+ #include "we_wmi_system.h"
42+ #include "we_wmi_thermalzone.h"
43+ #include "we_wmi_service.h"
44+
3845static int we_timer_cpu_metrics_cb (struct flb_input_instance * ins ,
3946 struct flb_config * config , void * in_context )
4047{
@@ -125,6 +132,16 @@ static int we_timer_wmi_system_metrics_cb(struct flb_input_instance *ins,
125132 return 0 ;
126133}
127134
135+ static int we_timer_wmi_service_metrics_cb (struct flb_input_instance * ins ,
136+ struct flb_config * config , void * in_context )
137+ {
138+ struct flb_ne * ctx = in_context ;
139+
140+ we_wmi_service_update (ctx );
141+
142+ return 0 ;
143+ }
144+
128145struct flb_we_callback {
129146 char * name ;
130147 void (* func )(char * , void * , void * );
@@ -240,6 +257,13 @@ static void we_wmi_system_update_cb(char *name, void *p1, void *p2)
240257 we_wmi_system_update (ctx );
241258}
242259
260+ static void we_wmi_service_update_cb (char * name , void * p1 , void * p2 )
261+ {
262+ struct flb_we * ctx = p1 ;
263+
264+ we_wmi_service_update (ctx );
265+ }
266+
243267static int we_update_cb (struct flb_we * ctx , char * name )
244268{
245269 int ret ;
@@ -262,6 +286,7 @@ struct flb_we_callback ne_callbacks[] = {
262286 { "thermalzone" , we_wmi_thermalzone_update_cb },
263287 { "logon" , we_wmi_logon_update_cb },
264288 { "system" , we_wmi_system_update_cb },
289+ { "service" , we_wmi_service_update_cb },
265290 { 0 }
266291};
267292
@@ -295,6 +320,7 @@ static int in_we_init(struct flb_input_instance *in,
295320 ctx -> coll_wmi_cpu_info_fd = -1 ;
296321 ctx -> coll_wmi_logon_fd = -1 ;
297322 ctx -> coll_wmi_system_fd = -1 ;
323+ ctx -> coll_wmi_service_fd = -1 ;
298324
299325 ctx -> callback = flb_callback_create (in -> name );
300326 if (!ctx -> callback ) {
@@ -574,6 +600,31 @@ static int in_we_init(struct flb_input_instance *in,
574600 return -1 ;
575601 }
576602 }
603+ else if (strncmp (entry -> str , "service" , 7 ) == 0 ) {
604+ if (ctx -> wmi_service_scrape_interval == 0 ) {
605+ flb_plg_debug (ctx -> ins , "enabled metrics %s" , entry -> str );
606+ metric_idx = 9 ;
607+ }
608+ else {
609+ /* Create the service collector */
610+ ret = flb_input_set_collector_time (in ,
611+ we_timer_wmi_service_metrics_cb ,
612+ ctx -> wmi_service_scrape_interval , 0 ,
613+ config );
614+ if (ret == -1 ) {
615+ flb_plg_error (ctx -> ins ,
616+ "could not set service collector for Windows Exporter Metrics plugin" );
617+ return -1 ;
618+ }
619+ ctx -> coll_wmi_service_fd = ret ;
620+ }
621+
622+ /* Initialize service metric collectors */
623+ ret = we_wmi_service_init (ctx );
624+ if (ret ) {
625+ return -1 ;
626+ }
627+ }
577628 else {
578629 flb_plg_warn (ctx -> ins , "Unknown metrics: %s" , entry -> str );
579630 metric_idx = -1 ;
@@ -644,6 +695,9 @@ static int in_we_exit(void *data, struct flb_config *config)
644695 else if (strncmp (entry -> str , "system" , 6 ) == 0 ) {
645696 we_wmi_system_exit (ctx );
646697 }
698+ else if (strncmp (entry -> str , "service" , 7 ) == 0 ) {
699+ we_wmi_service_exit (ctx );
700+ }
647701 else {
648702 flb_plg_warn (ctx -> ins , "Unknown metrics: %s" , entry -> str );
649703 }
@@ -681,6 +735,9 @@ static int in_we_exit(void *data, struct flb_config *config)
681735 if (ctx -> coll_wmi_system_fd != -1 ) {
682736 we_wmi_system_exit (ctx );
683737 }
738+ if (ctx -> coll_wmi_service_fd != -1 ) {
739+ we_wmi_service_exit (ctx );
740+ }
684741
685742 flb_we_config_destroy (ctx );
686743
@@ -721,6 +778,9 @@ static void in_we_pause(void *data, struct flb_config *config)
721778 if (ctx -> coll_wmi_system_fd != -1 ) {
722779 flb_input_collector_pause (ctx -> coll_wmi_system_fd , ctx -> ins );
723780 }
781+ if (ctx -> coll_wmi_service_fd != -1 ) {
782+ flb_input_collector_pause (ctx -> coll_wmi_service_fd , ctx -> ins );
783+ }
724784}
725785
726786static void in_we_resume (void * data , struct flb_config * config )
@@ -757,6 +817,9 @@ static void in_we_resume(void *data, struct flb_config *config)
757817 if (ctx -> coll_wmi_system_fd != -1 ) {
758818 flb_input_collector_resume (ctx -> coll_wmi_system_fd , ctx -> ins );
759819 }
820+ if (ctx -> coll_wmi_service_fd != -1 ) {
821+ flb_input_collector_resume (ctx -> coll_wmi_service_fd , ctx -> ins );
822+ }
760823}
761824
762825/* Configuration properties map */
@@ -822,9 +885,14 @@ static struct flb_config_map config_map[] = {
822885 0 , FLB_TRUE , offsetof(struct flb_we , wmi_system_scrape_interval ),
823886 "scrape interval to collect system metrics from the node."
824887 },
888+ {
889+ FLB_CONFIG_MAP_TIME , "collector.service.scrape_interval" , "0" ,
890+ 0 , FLB_TRUE , offsetof(struct flb_we , wmi_service_scrape_interval ),
891+ "scrape interval to collect service metrics from the node."
892+ },
825893 {
826894 FLB_CONFIG_MAP_CLIST , "metrics" ,
827- "cpu,cpu_info,os,net,logical_disk,cs,thermalzone,logon,system" ,
895+ "cpu,cpu_info,os,net,logical_disk,cs,thermalzone,logon,system,service " ,
828896 0 , FLB_TRUE , offsetof(struct flb_we , metrics ),
829897 "Comma separated list of keys to enable metrics."
830898 },
@@ -843,6 +911,11 @@ static struct flb_config_map config_map[] = {
843911 0 , FLB_TRUE , offsetof(struct flb_we , raw_allowing_nic ),
844912 "Specify to be scribable regex for net metrics by name of NIC."
845913 },
914+ {
915+ FLB_CONFIG_MAP_STR , "we.service.where" , NULL ,
916+ 0 , FLB_TRUE , offsetof(struct flb_we , raw_where_clause ),
917+ "Specify the where clause for retrieving service metrics."
918+ },
846919 /* EOF */
847920 {0 }
848921};
0 commit comments