2021-12-18 18:01:29 +00:00
//go:build windows
2018-11-30 00:51:12 +00:00
// +build windows
2017-10-16 17:37:14 +00:00
package collector
import (
2021-01-30 10:16:53 +00:00
"github.com/prometheus-community/windows_exporter/log"
2017-10-16 17:37:14 +00:00
"github.com/prometheus/client_golang/prometheus"
2023-03-12 00:27:31 +00:00
"github.com/yusufpapurcu/wmi"
2017-10-16 17:37:14 +00:00
)
// A NETFramework_NETCLRInteropCollector is a Prometheus collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics
type NETFramework_NETCLRInteropCollector struct {
NumberofCCWs * prometheus . Desc
Numberofmarshalling * prometheus . Desc
NumberofStubs * prometheus . Desc
}
// NewNETFramework_NETCLRInteropCollector ...
func NewNETFramework_NETCLRInteropCollector ( ) ( Collector , error ) {
const subsystem = "netframework_clrinterop"
return & NETFramework_NETCLRInteropCollector {
NumberofCCWs : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "com_callable_wrappers_total" ) ,
"Displays the current number of COM callable wrappers (CCWs). A CCW is a proxy for a managed object being referenced from an unmanaged COM client." ,
[ ] string { "process" } ,
nil ,
) ,
Numberofmarshalling : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "interop_marshalling_total" ) ,
"Displays the total number of times arguments and return values have been marshaled from managed to unmanaged code, and vice versa, since the application started." ,
[ ] string { "process" } ,
nil ,
) ,
NumberofStubs : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "interop_stubs_created_total" ) ,
"Displays the current number of stubs created by the common language runtime. Stubs are responsible for marshaling arguments and return values from managed to unmanaged code, and vice versa, during a COM interop call or a platform invoke call." ,
[ ] string { "process" } ,
nil ,
) ,
} , nil
}
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
2019-04-05 13:59:40 +00:00
func ( c * NETFramework_NETCLRInteropCollector ) Collect ( ctx * ScrapeContext , ch chan <- prometheus . Metric ) error {
2017-10-16 17:37:14 +00:00
if desc , err := c . collect ( ch ) ; err != nil {
2018-04-05 05:27:26 +00:00
log . Error ( "failed collecting win32_perfrawdata_netframework_netclrinterop metrics:" , desc , err )
2017-10-16 17:37:14 +00:00
return err
}
return nil
}
type Win32_PerfRawData_NETFramework_NETCLRInterop struct {
Name string
NumberofCCWs uint32
Numberofmarshalling uint32
NumberofStubs uint32
NumberofTLBexportsPersec uint32
NumberofTLBimportsPersec uint32
}
func ( c * NETFramework_NETCLRInteropCollector ) collect ( ch chan <- prometheus . Metric ) ( * prometheus . Desc , error ) {
var dst [ ] Win32_PerfRawData_NETFramework_NETCLRInterop
2018-06-06 08:31:50 +00:00
q := queryAll ( & dst )
2017-10-16 17:37:14 +00:00
if err := wmi . Query ( q , & dst ) ; err != nil {
return nil , err
}
for _ , process := range dst {
if process . Name == "_Global_" {
continue
}
ch <- prometheus . MustNewConstMetric (
c . NumberofCCWs ,
prometheus . CounterValue ,
float64 ( process . NumberofCCWs ) ,
process . Name ,
)
ch <- prometheus . MustNewConstMetric (
c . Numberofmarshalling ,
prometheus . CounterValue ,
float64 ( process . Numberofmarshalling ) ,
process . Name ,
)
ch <- prometheus . MustNewConstMetric (
c . NumberofStubs ,
prometheus . CounterValue ,
float64 ( process . NumberofStubs ) ,
process . Name ,
)
}
return nil , nil
}