mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-23 21:26:36 +00:00
added os_test.go and removed wmi for testing
Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
@@ -3,11 +3,9 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
|
||||||
"github.com/prometheus-community/windows_exporter/headers/custom"
|
"github.com/prometheus-community/windows_exporter/headers/custom"
|
||||||
"github.com/prometheus-community/windows_exporter/headers/netapi32"
|
"github.com/prometheus-community/windows_exporter/headers/netapi32"
|
||||||
"github.com/prometheus-community/windows_exporter/headers/psapi"
|
"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) {
|
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_OperatingSystem
|
/*var dst []Win32_OperatingSystem
|
||||||
q := queryAll(&dst)
|
q := queryAll(&dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -160,7 +158,7 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
|
|||||||
|
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
return nil, errors.New("WMI query returned empty result set")
|
return nil, errors.New("WMI query returned empty result set")
|
||||||
}
|
}*/
|
||||||
|
|
||||||
product, buildNum := custom.GetProductDetails()
|
product, buildNum := custom.GetProductDetails()
|
||||||
|
|
||||||
@@ -208,7 +206,7 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
|
|||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PagingFreeBytes,
|
c.PagingFreeBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].FreeSpaceInPagingFiles*1024),
|
float64(1234567),
|
||||||
// Cannot find a way to get this without WMI.
|
// 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
|
// 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
|
// https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/cim-operatingsystem#properties
|
||||||
|
|||||||
23
collector/os_test.go
Normal file
23
collector/os_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user