From 3da11645cfe0d42bf5d26d4da5acde7c162f60ab Mon Sep 17 00:00:00 2001 From: retryW Date: Wed, 13 Jan 2021 13:54:51 +1100 Subject: [PATCH] added os_test.go and removed wmi for testing Signed-off-by: Ben Ridley --- collector/os.go | 8 +++----- collector/os_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 collector/os_test.go diff --git a/collector/os.go b/collector/os.go index 9c9c6af0..9245f86a 100644 --- a/collector/os.go +++ b/collector/os.go @@ -3,11 +3,9 @@ package collector import ( - "errors" "fmt" "time" - "github.com/StackExchange/wmi" "github.com/prometheus-community/windows_exporter/headers/custom" "github.com/prometheus-community/windows_exporter/headers/netapi32" "github.com/prometheus-community/windows_exporter/headers/psapi" @@ -152,7 +150,7 @@ type Win32_OperatingSystem struct { } func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { - var dst []Win32_OperatingSystem + /*var dst []Win32_OperatingSystem q := queryAll(&dst) if err := wmi.Query(q, &dst); err != nil { return nil, err @@ -160,7 +158,7 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er if len(dst) == 0 { return nil, errors.New("WMI query returned empty result set") - } + }*/ product, buildNum := custom.GetProductDetails() @@ -208,7 +206,7 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er ch <- prometheus.MustNewConstMetric( c.PagingFreeBytes, prometheus.GaugeValue, - float64(dst[0].FreeSpaceInPagingFiles*1024), + float64(1234567), // Cannot find a way to get this without WMI. // Can get from CIM_OperatingSystem which is where WMI gets it from, but I can't figure out how to access this from cimwin32.dll // https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/cim-operatingsystem#properties diff --git a/collector/os_test.go b/collector/os_test.go new file mode 100644 index 00000000..2e669486 --- /dev/null +++ b/collector/os_test.go @@ -0,0 +1,23 @@ +package collector + +import ( + "testing" + + "github.com/prometheus/client_golang/prometheus" +) + +func BenchmarkOsCollect(b *testing.B) { + o, err := NewOSCollector() + if err != nil { + b.Error(err) + } + metrics := make(chan prometheus.Metric) + go func() { + for { + <-metrics + } + }() + for i := 0; i < b.N; i++ { + o.Collect(&ScrapeContext{}, metrics) + } +}