@@ -73,8 +73,13 @@ static int nif;
7373static int pnif ;
7474#endif /* HAVE_PERFSTAT */
7575
76+ #if KERNEL_WIN32
77+ #include "utils_wmi.h"
78+ static wmi_connection_t * wmi ;
79+ #endif
80+
7681#if !HAVE_GETIFADDRS && !KERNEL_LINUX && !HAVE_LIBKSTAT && \
77- !HAVE_LIBSTATGRAB && !HAVE_PERFSTAT
82+ !HAVE_LIBSTATGRAB && !HAVE_PERFSTAT && ! KERNEL_WIN32
7883#error "No applicable input method."
7984#endif
8085
@@ -151,7 +156,18 @@ static int interface_init(void) {
151156
152157 return 0 ;
153158} /* int interface_init */
154- #endif /* HAVE_LIBKSTAT */
159+ /* #endif HAVE_LIBKSTAT */
160+ #elif KERNEL_WIN32
161+ static int interface_init (void ) {
162+ wmi = wmi_connect ();
163+ return 0 ;
164+ }
165+
166+ static int interface_shutdown (void ) {
167+ wmi_release (wmi );
168+ return 0 ;
169+ } /* int interface_shutdown */
170+ #endif /* KERNEL_WIN32 */
155171
156172static void if_submit (const char * dev , const char * type , derive_t rx ,
157173 derive_t tx ) {
@@ -378,16 +394,64 @@ static int interface_read(void) {
378394 if_submit (ifstat [i ].name , "if_errors" , ifstat [i ].ierrors ,
379395 ifstat [i ].oerrors );
380396 }
381- #endif /* HAVE_PERFSTAT */
397+ /* #endif HAVE_PERFSTAT */
398+ #elif KERNEL_WIN32
399+ const char * statement = "select * from Win32_PerfRawData_Tcpip_NetworkInterface" ;
400+ wmi_result_list_t * results ;
401+ results = wmi_query (wmi , statement );
402+
403+ if (results -> count == 0 ) {
404+ WARNING ("interface plugin: no results for query %s." , statement );
405+ wmi_result_list_release (results );
406+ return 0 ;
407+ }
408+
409+ wmi_result_t * result ;
410+ while ((result = wmi_get_next_result (results ))) {
411+ VARIANT rx_value_v ;
412+ VARIANT tx_value_v ;
413+ VARIANT plugin_instance_v ;
414+ char * plugin_instance_s = NULL ;
415+
416+ if (wmi_result_get_value (result , "BytesReceivedPersec" , & rx_value_v ) != 0 ) {
417+ VariantClear (& rx_value_v );
418+ ERROR ("interface plugin: failed to read field 'BytesReceivedPersec'" );
419+ continue ;
420+ }
421+ if (wmi_result_get_value (result , "BytesSentPersec" , & tx_value_v ) != 0 ) {
422+ VariantClear (& rx_value_v );
423+ VariantClear (& tx_value_v );
424+ ERROR ("interface plugin: failed to read field 'BytesSentPersec'" );
425+ continue ;
426+ }
427+ if (wmi_result_get_value (result , "Name" , & plugin_instance_v ) != 0 ) {
428+ ERROR ("interface plugin: failed to read field 'Name'" );
429+ }
430+ plugin_instance_s = variant_get_string (& plugin_instance_v );
431+ if (plugin_instance_s == NULL ) {
432+ ERROR ("interface plugin: failed to convert plugin_instance to string" );
433+ }
434+ if_submit (plugin_instance_s , "if_octets" , variant_get_int64 (& rx_value_v ), variant_get_int64 (& tx_value_v ));
435+ free (plugin_instance_s );
436+ VariantClear (& rx_value_v );
437+ VariantClear (& tx_value_v );
438+ VariantClear (& plugin_instance_v );
439+ wmi_result_release (result );
440+ }
441+ wmi_result_list_release (results );
442+ #endif /* KERNEL_WIN32 */
382443
383444 return 0 ;
384445} /* int interface_read */
385446
386447void module_register (void ) {
387448 plugin_register_config ("interface" , interface_config , config_keys ,
388449 config_keys_num );
389- #if HAVE_LIBKSTAT
450+ #if HAVE_LIBKSTAT || KERNEL_WIN32
390451 plugin_register_init ("interface" , interface_init );
452+ #endif
453+ #if KERNEL_WIN32
454+ plugin_register_shutdown ("interface" , interface_shutdown );
391455#endif
392456 plugin_register_read ("interface" , interface_read );
393457} /* void module_register */
0 commit comments