mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-23 05:06:36 +00:00
Add benchmark for each collector
Benchmarks will allow for easier identification of slow collectors. Additionally, they increase test coverage of the collectors, with some collectors now reaching 80-95% coverage with this change. Collector benchmarks have been structed so that common functionality is present in `collector/collector_test.go` as is done with non-test functionality in `collector/collector.go`. Test logic that is specific to individual collectors is present in the collector test file (E.G. `collector/process_test.go` for the Process collector). Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
3
Makefile
3
Makefile
@@ -8,6 +8,9 @@ windows_exporter.exe: **/*.go
|
|||||||
test:
|
test:
|
||||||
go test -v ./...
|
go test -v ./...
|
||||||
|
|
||||||
|
bench:
|
||||||
|
go test -v -bench='benchmark(cpu|logicaldisk|logon|memory|net|process|service|system|tcp|time)collector' ./...
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
golangci-lint -c .golangci.yaml run
|
golangci-lint -c .golangci.yaml run
|
||||||
|
|
||||||
|
|||||||
9
collector/ad_test.go
Normal file
9
collector/ad_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkADCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "ad", NewADCollector)
|
||||||
|
}
|
||||||
9
collector/adfs_test.go
Normal file
9
collector/adfs_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkADFSCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "adfs", newADFSCollector)
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExpandChildCollectors(t *testing.T) {
|
func TestExpandChildCollectors(t *testing.T) {
|
||||||
@@ -32,3 +34,27 @@ func TestExpandChildCollectors(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkCollector(b *testing.B, name string, collectFunc func() (Collector, error)) {
|
||||||
|
// Create perflib scrape context. Some perflib collectors required a correct context,
|
||||||
|
// or will fail during benchmark.
|
||||||
|
scrapeContext, err := PrepareScrapeContext([]string{name})
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
}
|
||||||
|
c, err := collectFunc()
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics := make(chan prometheus.Metric)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
<-metrics
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
c.Collect(scrapeContext, metrics)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
9
collector/container_test.go
Normal file
9
collector/container_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkContainerCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "container", NewContainerMetricsCollector)
|
||||||
|
}
|
||||||
9
collector/cpu_test.go
Normal file
9
collector/cpu_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkCPUCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "cpu", newCPUCollector)
|
||||||
|
}
|
||||||
@@ -2,22 +2,8 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkCsCollect(b *testing.B) {
|
func BenchmarkCsCollector(b *testing.B) {
|
||||||
c, err := NewCSCollector()
|
benchmarkCollector(b, "cs", NewCSCollector)
|
||||||
if err != nil {
|
|
||||||
b.Error(err)
|
|
||||||
}
|
|
||||||
metrics := make(chan prometheus.Metric)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
<-metrics
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
c.Collect(&ScrapeContext{}, metrics)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
9
collector/dfsr_test.go
Normal file
9
collector/dfsr_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkDFSRCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "dfsr", NewDFSRCollector)
|
||||||
|
}
|
||||||
9
collector/dhcp_test.go
Normal file
9
collector/dhcp_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkDHCPCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "dhcp", NewDhcpCollector)
|
||||||
|
}
|
||||||
9
collector/dns_test.go
Normal file
9
collector/dns_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkDNSCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "dns", NewDNSCollector)
|
||||||
|
}
|
||||||
9
collector/exchange_test.go
Normal file
9
collector/exchange_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkExchangeCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "exchange", newExchangeCollector)
|
||||||
|
}
|
||||||
9
collector/fsrmquota_test.go
Normal file
9
collector/fsrmquota_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkFsrmQuotaCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "fsrmquota", newFSRMQuotaCollector)
|
||||||
|
}
|
||||||
9
collector/hyperv_test.go
Normal file
9
collector/hyperv_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkHypervCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "hyperv", NewHyperVCollector)
|
||||||
|
}
|
||||||
9
collector/iis_test.go
Normal file
9
collector/iis_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkIISCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "iis", NewIISCollector)
|
||||||
|
}
|
||||||
13
collector/logical_disk_test.go
Normal file
13
collector/logical_disk_test.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkLogicalDiskCollector(b *testing.B) {
|
||||||
|
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all disks.
|
||||||
|
localVolumeWhitelist := ".+"
|
||||||
|
volumeWhitelist = &localVolumeWhitelist
|
||||||
|
|
||||||
|
benchmarkCollector(b, "logical_disk", NewLogicalDiskCollector)
|
||||||
|
}
|
||||||
10
collector/logon_test.go
Normal file
10
collector/logon_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkLogonCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewLogonCollector)
|
||||||
|
}
|
||||||
9
collector/memory_test.go
Normal file
9
collector/memory_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkMemoryCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "memory", NewMemoryCollector)
|
||||||
|
}
|
||||||
10
collector/msmq_test.go
Normal file
10
collector/msmq_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkMsmqCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewMSMQCollector)
|
||||||
|
}
|
||||||
9
collector/mssql_test.go
Normal file
9
collector/mssql_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkMSSQLCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "mssql", NewMSSQLCollector)
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestNetworkToInstanceName(t *testing.T) {
|
func TestNetworkToInstanceName(t *testing.T) {
|
||||||
data := map[string]string{
|
data := map[string]string{
|
||||||
@@ -15,3 +17,10 @@ func TestNetworkToInstanceName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkNetCollector(b *testing.B) {
|
||||||
|
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all interfaces.
|
||||||
|
localNicWhitelist := ".+"
|
||||||
|
nicWhitelist = &localNicWhitelist
|
||||||
|
benchmarkCollector(b, "net", NewNetworkCollector)
|
||||||
|
}
|
||||||
|
|||||||
10
collector/netframework_clrexceptions_test.go
Normal file
10
collector/netframework_clrexceptions_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNetFrameworkNETCLRExceptionsCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRExceptionsCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrinterop_test.go
Normal file
10
collector/netframework_clrinterop_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRInteropCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRInteropCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrjit_test.go
Normal file
10
collector/netframework_clrjit_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRJitCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRJitCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrloading_test.go
Normal file
10
collector/netframework_clrloading_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRLoadingCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRLoadingCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrlocksandthreads_test.go
Normal file
10
collector/netframework_clrlocksandthreads_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRLocksAndThreadsCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRLocksAndThreadsCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrmemory_test.go
Normal file
10
collector/netframework_clrmemory_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRMemoryCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRMemoryCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrremoting_test.go
Normal file
10
collector/netframework_clrremoting_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRRemotingCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRRemotingCollector)
|
||||||
|
}
|
||||||
10
collector/netframework_clrsecurity_test.go
Normal file
10
collector/netframework_clrsecurity_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkNETFrameworkNETCLRSecurityCollector(b *testing.B) {
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", NewNETFramework_NETCLRSecurityCollector)
|
||||||
|
}
|
||||||
@@ -2,23 +2,8 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkOsCollect(b *testing.B) {
|
func BenchmarkOSCollector(b *testing.B) {
|
||||||
o, err := NewOSCollector()
|
benchmarkCollector(b, "os", NewOSCollector)
|
||||||
if err != nil {
|
|
||||||
b.Error(err)
|
|
||||||
}
|
|
||||||
metrics := make(chan prometheus.Metric)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
<-metrics
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
s, err := PrepareScrapeContext([]string{"os"})
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
o.Collect(s, metrics)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
collector/process_test.go
Normal file
14
collector/process_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkProcessCollector(b *testing.B) {
|
||||||
|
// Whitelist is not set in testing context (kingpin flags not parsed), causing the collector to skip all processes.
|
||||||
|
localProcessWhitelist := ".+"
|
||||||
|
processWhitelist = &localProcessWhitelist
|
||||||
|
|
||||||
|
// No context name required as collector source is WMI
|
||||||
|
benchmarkCollector(b, "", newProcessCollector)
|
||||||
|
}
|
||||||
9
collector/remote_fx_test.go
Normal file
9
collector/remote_fx_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkRemoteFXCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "remote_fx", NewRemoteFx)
|
||||||
|
}
|
||||||
9
collector/service_test.go
Normal file
9
collector/service_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkServiceCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "service", NewserviceCollector)
|
||||||
|
}
|
||||||
9
collector/smtp_test.go
Normal file
9
collector/smtp_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkSmtpCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "smtp", NewSMTPCollector)
|
||||||
|
}
|
||||||
9
collector/system_test.go
Normal file
9
collector/system_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkSystemCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "system", NewSystemCollector)
|
||||||
|
}
|
||||||
9
collector/tcp_test.go
Normal file
9
collector/tcp_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkTCPCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "tcp", NewTCPCollector)
|
||||||
|
}
|
||||||
9
collector/terminal_services_test.go
Normal file
9
collector/terminal_services_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkTerminalServicesCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "terminal_services", NewTerminalServicesCollector)
|
||||||
|
}
|
||||||
9
collector/thermalzone_test.go
Normal file
9
collector/thermalzone_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkThermalZoneCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "thermalzone", NewThermalZoneCollector)
|
||||||
|
}
|
||||||
9
collector/time_test.go
Normal file
9
collector/time_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkTimeCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "time", newTimeCollector)
|
||||||
|
}
|
||||||
9
collector/vmware_test.go
Normal file
9
collector/vmware_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkVmwareCollector(b *testing.B) {
|
||||||
|
benchmarkCollector(b, "vmware", NewVmwareCollector)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user