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 (
2023-04-22 10:17:51 +00:00
"github.com/go-kit/log"
"github.com/go-kit/log/level"
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 {
2023-04-22 10:17:51 +00:00
logger log . Logger
2017-10-16 17:37:14 +00:00
NumberofCCWs * prometheus . Desc
Numberofmarshalling * prometheus . Desc
NumberofStubs * prometheus . Desc
}
2022-12-21 05:44:29 +00:00
// newNETFramework_NETCLRInteropCollector ...
2023-04-22 10:17:51 +00:00
func newNETFramework_NETCLRInteropCollector ( logger log . Logger ) ( Collector , error ) {
2017-10-16 17:37:14 +00:00
const subsystem = "netframework_clrinterop"
return & NETFramework_NETCLRInteropCollector {
2023-04-22 10:17:51 +00:00
logger : log . With ( logger , "collector" , subsystem ) ,
2017-10-16 17:37:14 +00:00
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 {
2023-06-08 00:29:50 +00:00
_ = level . Error ( c . logger ) . Log ( "failed collecting win32_perfrawdata_netframework_netclrinterop metrics" , "desc" , desc , "err" , 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
2023-04-22 10:17:51 +00:00
q := queryAll ( & dst , c . logger )
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
}