From d68a1644fabdfbc645f7caad74c6294cfb1b6eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Mon, 9 Dec 2024 18:53:51 +0100 Subject: [PATCH] process: fix metric labels for multiple process instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- .run/all.run.xml | 4 +-- cmd/windows_exporter/main.go | 25 ++++++------------- internal/collector/ad/ad.go | 3 +-- internal/collector/adcs/adcs.go | 3 +-- internal/collector/adfs/adfs.go | 5 ++-- internal/collector/cache/cache.go | 3 +-- internal/collector/dfsr/dfsr.go | 7 +++--- internal/collector/dhcp/dhcp.go | 3 +-- internal/collector/dns/dns.go | 3 +-- .../exchange/exchange_active_sync.go | 3 +-- .../exchange/exchange_ad_access_processes.go | 3 +-- .../exchange/exchange_autodiscover.go | 3 +-- .../exchange/exchange_availability_service.go | 3 +-- .../collector/exchange/exchange_http_proxy.go | 3 +-- .../exchange/exchange_mapi_http_emsmdb.go | 3 +-- .../exchange/exchange_outlook_web_access.go | 3 +-- .../exchange/exchange_rpc_client_access.go | 3 +-- .../exchange/exchange_transport_queues.go | 3 +-- .../exchange/exchange_workload_management.go | 3 +-- internal/collector/memory/memory.go | 3 +-- .../collector/mssql/mssql_access_methods.go | 3 +-- .../mssql/mssql_availability_replica.go | 3 +-- .../collector/mssql/mssql_buffer_manager.go | 3 +-- internal/collector/mssql/mssql_database.go | 3 +-- .../collector/mssql/mssql_database_replica.go | 3 +-- .../mssql/mssql_general_statistics.go | 3 +-- internal/collector/mssql/mssql_locks.go | 3 +-- .../collector/mssql/mssql_memory_manager.go | 3 +-- internal/collector/mssql/mssql_sql_errors.go | 3 +-- internal/collector/mssql/mssql_sql_stats.go | 3 +-- .../collector/mssql/mssql_transactions.go | 3 +-- internal/collector/mssql/mssql_wait_stats.go | 3 +-- internal/collector/nps/nps.go | 5 ++-- .../performancecounter/performancecounter.go | 2 -- internal/collector/vmware/vmware.go | 5 ++-- internal/types/errors.go | 7 ++++++ pkg/collector/collect.go | 4 +-- pkg/collector/collection.go | 15 ++++++++++- pkg/public/error.go | 22 ---------------- 39 files changed, 70 insertions(+), 115 deletions(-) delete mode 100644 pkg/public/error.go diff --git a/.run/all.run.xml b/.run/all.run.xml index 65ec0a71d..5b5035b88 100644 --- a/.run/all.run.xml +++ b/.run/all.run.xml @@ -2,7 +2,7 @@ - + @@ -10,4 +10,4 @@ - \ No newline at end of file + diff --git a/cmd/windows_exporter/main.go b/cmd/windows_exporter/main.go index 0d6b9919d..99e3fc63d 100644 --- a/cmd/windows_exporter/main.go +++ b/cmd/windows_exporter/main.go @@ -20,10 +20,6 @@ package main //goland:noinspection GoUnsortedImport //nolint:gofumpt import ( - // Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts. - "github.com/prometheus-community/windows_exporter/internal/windowsservice" - "github.com/prometheus-community/windows_exporter/pkg/public" - "context" "errors" "fmt" @@ -38,6 +34,9 @@ import ( "strings" "time" + // Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts. + "github.com/prometheus-community/windows_exporter/internal/windowsservice" + "github.com/alecthomas/kingpin/v2" "github.com/prometheus-community/windows_exporter/internal/config" "github.com/prometheus-community/windows_exporter/internal/httphandler" @@ -208,19 +207,11 @@ func run() int { // Initialize collectors before loading if err = collectors.Build(logger); err != nil { for _, err := range utils.SplitError(err) { - for _, ignoreErr := range public.ErrsBuildCanIgnored { - if errors.Is(err, ignoreErr) { - logger.Warn("couldn't initialize collector", - slog.Any("err", err), - ) - } else { - logger.Error("couldn't initialize collector", - slog.Any("err", err), - ) - - return 1 - } - } + logger.Error("couldn't initialize collector", + slog.Any("err", err), + ) + + return 1 } } diff --git a/internal/collector/ad/ad.go b/internal/collector/ad/ad.go index 81b30f67f..b7edf0cf1 100644 --- a/internal/collector/ad/ad.go +++ b/internal/collector/ad/ad.go @@ -23,7 +23,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -672,7 +671,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { data, ok := perfData["NTDS"] if !ok { - return fmt.Errorf("failed to collect DirectoryServices (AD) metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect DirectoryServices (AD) metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/adcs/adcs.go b/internal/collector/adcs/adcs.go index 0a0501e66..dd3ce99e5 100644 --- a/internal/collector/adcs/adcs.go +++ b/internal/collector/adcs/adcs.go @@ -24,7 +24,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" "github.com/prometheus-community/windows_exporter/internal/utils" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -192,7 +191,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect Certification Authority (ADCS) metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect Certification Authority (ADCS) metrics: %w", types.ErrNoData) } for name, data := range perfData { diff --git a/internal/collector/adfs/adfs.go b/internal/collector/adfs/adfs.go index 5a92afae1..af57558e7 100644 --- a/internal/collector/adfs/adfs.go +++ b/internal/collector/adfs/adfs.go @@ -26,7 +26,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -436,13 +435,13 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { instanceKey := slices.Collect(maps.Keys(data)) if len(instanceKey) == 0 { - return fmt.Errorf("failed to collect ADFS metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect ADFS metrics: %w", types.ErrNoData) } adfsData, ok := data[instanceKey[0]] if !ok { - return fmt.Errorf("failed to collect ADFS metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect ADFS metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/cache/cache.go b/internal/collector/cache/cache.go index 3220429d5..e894e112e 100644 --- a/internal/collector/cache/cache.go +++ b/internal/collector/cache/cache.go @@ -23,7 +23,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -323,7 +322,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { cacheData, ok := data[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect Cache metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect Cache metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/dfsr/dfsr.go b/internal/collector/dfsr/dfsr.go index fbebac9be..272756a39 100644 --- a/internal/collector/dfsr/dfsr.go +++ b/internal/collector/dfsr/dfsr.go @@ -26,7 +26,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -544,7 +543,7 @@ func (c *Collector) collectPDHConnection(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect DFS Replication Connections metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect DFS Replication Connections metrics: %w", types.ErrNoData) } for name, connection := range perfData { @@ -622,7 +621,7 @@ func (c *Collector) collectPDHFolder(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect DFS Replicated Folders metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect DFS Replicated Folders metrics: %w", types.ErrNoData) } for name, folder := range perfData { @@ -826,7 +825,7 @@ func (c *Collector) collectPDHVolume(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect DFS Replication Volumes metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect DFS Replication Volumes metrics: %w", types.ErrNoData) } for name, volume := range perfData { diff --git a/internal/collector/dhcp/dhcp.go b/internal/collector/dhcp/dhcp.go index 42f0ad187..0d67d7007 100644 --- a/internal/collector/dhcp/dhcp.go +++ b/internal/collector/dhcp/dhcp.go @@ -23,7 +23,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -289,7 +288,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect DHCP Server metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect DHCP Server metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/dns/dns.go b/internal/collector/dns/dns.go index 4597834df..3e5dee7d5 100644 --- a/internal/collector/dns/dns.go +++ b/internal/collector/dns/dns.go @@ -23,7 +23,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -285,7 +284,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect DNS metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect DNS metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/exchange/exchange_active_sync.go b/internal/collector/exchange/exchange_active_sync.go index 77072d687..06c2e87ee 100644 --- a/internal/collector/exchange/exchange_active_sync.go +++ b/internal/collector/exchange/exchange_active_sync.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -73,7 +72,7 @@ func (c *Collector) collectActiveSync(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange ActiveSync metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange ActiveSync metrics: %w", types.ErrNoData) } for _, data := range perfData { diff --git a/internal/collector/exchange/exchange_ad_access_processes.go b/internal/collector/exchange/exchange_ad_access_processes.go index 7a3b58e1b..dbf41031e 100644 --- a/internal/collector/exchange/exchange_ad_access_processes.go +++ b/internal/collector/exchange/exchange_ad_access_processes.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -89,7 +88,7 @@ func (c *Collector) collectADAccessProcesses(ch chan<- prometheus.Metric) error } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange ADAccess Processes metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange ADAccess Processes metrics: %w", types.ErrNoData) } labelUseCount := make(map[string]int) diff --git a/internal/collector/exchange/exchange_autodiscover.go b/internal/collector/exchange/exchange_autodiscover.go index d75f0ce71..5e5f48131 100644 --- a/internal/collector/exchange/exchange_autodiscover.go +++ b/internal/collector/exchange/exchange_autodiscover.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -53,7 +52,7 @@ func (c *Collector) collectAutoDiscover(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange Autodiscover metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange Autodiscover metrics: %w", types.ErrNoData) } for _, data := range perfData { diff --git a/internal/collector/exchange/exchange_availability_service.go b/internal/collector/exchange/exchange_availability_service.go index 7a40deca4..7e57ee892 100644 --- a/internal/collector/exchange/exchange_availability_service.go +++ b/internal/collector/exchange/exchange_availability_service.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -53,7 +52,7 @@ func (c *Collector) collectAvailabilityService(ch chan<- prometheus.Metric) erro } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange Availability Service metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange Availability Service metrics: %w", types.ErrNoData) } for _, data := range perfData { diff --git a/internal/collector/exchange/exchange_http_proxy.go b/internal/collector/exchange/exchange_http_proxy.go index d25bf96cb..4e4691bce 100644 --- a/internal/collector/exchange/exchange_http_proxy.go +++ b/internal/collector/exchange/exchange_http_proxy.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -97,7 +96,7 @@ func (c *Collector) collectHTTPProxy(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange HttpProxy Service metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange HttpProxy Service metrics: %w", types.ErrNoData) } for name, data := range perfData { diff --git a/internal/collector/exchange/exchange_mapi_http_emsmdb.go b/internal/collector/exchange/exchange_mapi_http_emsmdb.go index e9ce3ff59..a36c1e372 100644 --- a/internal/collector/exchange/exchange_mapi_http_emsmdb.go +++ b/internal/collector/exchange/exchange_mapi_http_emsmdb.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -57,7 +56,7 @@ func (c *Collector) collectMapiHttpEmsmdb(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange MapiHttp Emsmdb metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange MapiHttp Emsmdb metrics: %w", types.ErrNoData) } for _, data := range perfData { diff --git a/internal/collector/exchange/exchange_outlook_web_access.go b/internal/collector/exchange/exchange_outlook_web_access.go index 750d99251..e3f1a4995 100644 --- a/internal/collector/exchange/exchange_outlook_web_access.go +++ b/internal/collector/exchange/exchange_outlook_web_access.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -65,7 +64,7 @@ func (c *Collector) collectOWA(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange OWA metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange OWA metrics: %w", types.ErrNoData) } for _, data := range perfData { diff --git a/internal/collector/exchange/exchange_rpc_client_access.go b/internal/collector/exchange/exchange_rpc_client_access.go index d62d2c954..f68ecaacc 100644 --- a/internal/collector/exchange/exchange_rpc_client_access.go +++ b/internal/collector/exchange/exchange_rpc_client_access.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -97,7 +96,7 @@ func (c *Collector) collectRPC(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange RpcClientAccess metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange RpcClientAccess metrics: %w", types.ErrNoData) } for _, data := range perfData { diff --git a/internal/collector/exchange/exchange_transport_queues.go b/internal/collector/exchange/exchange_transport_queues.go index 840cc4b14..34b6db683 100644 --- a/internal/collector/exchange/exchange_transport_queues.go +++ b/internal/collector/exchange/exchange_transport_queues.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -201,7 +200,7 @@ func (c *Collector) collectTransportQueues(ch chan<- prometheus.Metric) error { } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchangeTransport Queues metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchangeTransport Queues metrics: %w", types.ErrNoData) } for name, data := range perfData { diff --git a/internal/collector/exchange/exchange_workload_management.go b/internal/collector/exchange/exchange_workload_management.go index 2d2b0a2e9..5094b02d4 100644 --- a/internal/collector/exchange/exchange_workload_management.go +++ b/internal/collector/exchange/exchange_workload_management.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -89,7 +88,7 @@ func (c *Collector) collectWorkloadManagementWorkloads(ch chan<- prometheus.Metr } if len(perfData) == 0 { - return fmt.Errorf("failed to collect MSExchange WorkloadManagement Workloads metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect MSExchange WorkloadManagement Workloads metrics: %w", types.ErrNoData) } for name, data := range perfData { diff --git a/internal/collector/memory/memory.go b/internal/collector/memory/memory.go index beeb88ce1..a3eab5c77 100644 --- a/internal/collector/memory/memory.go +++ b/internal/collector/memory/memory.go @@ -28,7 +28,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -432,7 +431,7 @@ func (c *Collector) collectPDH(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect Memory metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect Memory metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/mssql/mssql_access_methods.go b/internal/collector/mssql/mssql_access_methods.go index 0337b30ca..b37a56b6b 100644 --- a/internal/collector/mssql/mssql_access_methods.go +++ b/internal/collector/mssql/mssql_access_methods.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -455,7 +454,7 @@ func (c *Collector) collectAccessMethods(ch chan<- prometheus.Metric) error { func (c *Collector) collectAccessMethodsInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_availability_replica.go b/internal/collector/mssql/mssql_availability_replica.go index a1bb4d87a..0817e11b4 100644 --- a/internal/collector/mssql/mssql_availability_replica.go +++ b/internal/collector/mssql/mssql_availability_replica.go @@ -22,7 +22,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" "github.com/prometheus-community/windows_exporter/internal/utils" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -141,7 +140,7 @@ func (c *Collector) collectAvailabilityReplica(ch chan<- prometheus.Metric) erro func (c *Collector) collectAvailabilityReplicaInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_buffer_manager.go b/internal/collector/mssql/mssql_buffer_manager.go index befb2b7ed..12e297c0f 100644 --- a/internal/collector/mssql/mssql_buffer_manager.go +++ b/internal/collector/mssql/mssql_buffer_manager.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -265,7 +264,7 @@ func (c *Collector) collectBufferManager(ch chan<- prometheus.Metric) error { func (c *Collector) collectBufferManagerInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_database.go b/internal/collector/mssql/mssql_database.go index 72c775c89..bc6a337fb 100644 --- a/internal/collector/mssql/mssql_database.go +++ b/internal/collector/mssql/mssql_database.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -493,7 +492,7 @@ func (c *Collector) collectDatabases(ch chan<- prometheus.Metric) error { func (c *Collector) collectDatabasesInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_database_replica.go b/internal/collector/mssql/mssql_database_replica.go index 96906b5da..d89f50856 100644 --- a/internal/collector/mssql/mssql_database_replica.go +++ b/internal/collector/mssql/mssql_database_replica.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -275,7 +274,7 @@ func (c *Collector) collectDatabaseReplica(ch chan<- prometheus.Metric) error { func (c *Collector) collectDatabaseReplicaInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_general_statistics.go b/internal/collector/mssql/mssql_general_statistics.go index abd37d9c9..4a8248606 100644 --- a/internal/collector/mssql/mssql_general_statistics.go +++ b/internal/collector/mssql/mssql_general_statistics.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -275,7 +274,7 @@ func (c *Collector) collectGeneralStatistics(ch chan<- prometheus.Metric) error func (c *Collector) collectGeneralStatisticsInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_locks.go b/internal/collector/mssql/mssql_locks.go index 6de3a038c..503befd67 100644 --- a/internal/collector/mssql/mssql_locks.go +++ b/internal/collector/mssql/mssql_locks.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -131,7 +130,7 @@ func (c *Collector) collectLocks(ch chan<- prometheus.Metric) error { func (c *Collector) collectLocksInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_memory_manager.go b/internal/collector/mssql/mssql_memory_manager.go index 91838316d..9d397629c 100644 --- a/internal/collector/mssql/mssql_memory_manager.go +++ b/internal/collector/mssql/mssql_memory_manager.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -238,7 +237,7 @@ func (c *Collector) collectMemoryManager(ch chan<- prometheus.Metric) error { func (c *Collector) collectMemoryManagerInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_sql_errors.go b/internal/collector/mssql/mssql_sql_errors.go index 8046acc5b..8f4392c51 100644 --- a/internal/collector/mssql/mssql_sql_errors.go +++ b/internal/collector/mssql/mssql_sql_errors.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -69,7 +68,7 @@ func (c *Collector) collectSQLErrors(ch chan<- prometheus.Metric) error { func (c *Collector) collectSQLErrorsInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_sql_stats.go b/internal/collector/mssql/mssql_sql_stats.go index 66673ce88..f68234952 100644 --- a/internal/collector/mssql/mssql_sql_stats.go +++ b/internal/collector/mssql/mssql_sql_stats.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -157,7 +156,7 @@ func (c *Collector) collectSQLStats(ch chan<- prometheus.Metric) error { func (c *Collector) collectSQLStatsInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_transactions.go b/internal/collector/mssql/mssql_transactions.go index cd0fe200d..fc8ecea7e 100644 --- a/internal/collector/mssql/mssql_transactions.go +++ b/internal/collector/mssql/mssql_transactions.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -177,7 +176,7 @@ func (c *Collector) collectTransactions(ch chan<- prometheus.Metric) error { // - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-transactions-object func (c *Collector) collectTransactionsInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/mssql/mssql_wait_stats.go b/internal/collector/mssql/mssql_wait_stats.go index 48b7ce192..720ac31f1 100644 --- a/internal/collector/mssql/mssql_wait_stats.go +++ b/internal/collector/mssql/mssql_wait_stats.go @@ -21,7 +21,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -167,7 +166,7 @@ func (c *Collector) collectWaitStats(ch chan<- prometheus.Metric) error { func (c *Collector) collectWaitStatsInstance(ch chan<- prometheus.Metric, sqlInstance string, perfDataCollector *perfdata.Collector) error { if perfDataCollector == nil { - return public.ErrCollectorNotInitialized + return types.ErrCollectorNotInitialized } perfData, err := perfDataCollector.Collect() diff --git a/internal/collector/nps/nps.go b/internal/collector/nps/nps.go index 9b53db55c..aa4e37a48 100644 --- a/internal/collector/nps/nps.go +++ b/internal/collector/nps/nps.go @@ -24,7 +24,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -315,7 +314,7 @@ func (c *Collector) collectAccept(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect NPS Authentication Server metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect NPS Authentication Server metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( @@ -407,7 +406,7 @@ func (c *Collector) collectAccounting(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect NPS Accounting Server metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect NPS Accounting Server metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/collector/performancecounter/performancecounter.go b/internal/collector/performancecounter/performancecounter.go index b00f5d610..99452a07b 100644 --- a/internal/collector/performancecounter/performancecounter.go +++ b/internal/collector/performancecounter/performancecounter.go @@ -174,8 +174,6 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { collector, err := perfdata.NewCollector(object.Object, object.Instances, counters) if err != nil { errs = append(errs, fmt.Errorf("failed collector for %s: %w", object.Name, err)) - - continue } if object.InstanceLabel == "" { diff --git a/internal/collector/vmware/vmware.go b/internal/collector/vmware/vmware.go index 8f31c8ac9..2aaf5687a 100644 --- a/internal/collector/vmware/vmware.go +++ b/internal/collector/vmware/vmware.go @@ -25,7 +25,6 @@ import ( "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" "github.com/prometheus-community/windows_exporter/internal/utils" - "github.com/prometheus-community/windows_exporter/pkg/public" "github.com/prometheus/client_golang/prometheus" ) @@ -268,7 +267,7 @@ func (c *Collector) collectMem(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceEmpty] if !ok { - return fmt.Errorf("failed to collect VM Memory metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect VM Memory metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( @@ -354,7 +353,7 @@ func (c *Collector) collectCpu(ch chan<- prometheus.Metric) error { data, ok := perfData[perfdata.InstanceTotal] if !ok { - return fmt.Errorf("failed to collect VM CPU metrics: %w", public.ErrNoData) + return fmt.Errorf("failed to collect VM CPU metrics: %w", types.ErrNoData) } ch <- prometheus.MustNewConstMetric( diff --git a/internal/types/errors.go b/internal/types/errors.go index 2ed131a0b..3694d7cc9 100644 --- a/internal/types/errors.go +++ b/internal/types/errors.go @@ -12,3 +12,10 @@ // limitations under the License. package types + +import "errors" + +var ( + ErrCollectorNotInitialized = errors.New("collector not initialized") + ErrNoData = errors.New("no data") +) diff --git a/pkg/collector/collect.go b/pkg/collector/collect.go index 36f6cac78..233bd27a7 100644 --- a/pkg/collector/collect.go +++ b/pkg/collector/collect.go @@ -25,7 +25,7 @@ import ( "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/perfdata" - "github.com/prometheus-community/windows_exporter/pkg/public" + "github.com/prometheus-community/windows_exporter/internal/types" "github.com/prometheus/client_golang/prometheus" ) @@ -204,7 +204,7 @@ func (c *Collection) collectCollector(ch chan<- prometheus.Metric, logger *slog. return pending } - if err != nil && !errors.Is(err, perfdata.ErrNoData) && !errors.Is(err, public.ErrNoData) { + if err != nil && !errors.Is(err, perfdata.ErrNoData) && !errors.Is(err, types.ErrNoData) { loggerFn := logger.Warn if errors.Is(err, perfdata.ErrPerformanceCounterNotInitialized) || errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE) { diff --git a/pkg/collector/collection.go b/pkg/collector/collection.go index fed7b81ef..8a47067ae 100644 --- a/pkg/collector/collection.go +++ b/pkg/collector/collection.go @@ -74,6 +74,7 @@ import ( "github.com/prometheus-community/windows_exporter/internal/collector/update" "github.com/prometheus-community/windows_exporter/internal/collector/vmware" "github.com/prometheus-community/windows_exporter/internal/mi" + "github.com/prometheus-community/windows_exporter/internal/perfdata" "github.com/prometheus-community/windows_exporter/internal/types" "github.com/prometheus/client_golang/prometheus" ) @@ -210,7 +211,6 @@ func (c *Collection) Build(logger *slog.Logger) error { wg.Add(len(c.collectors)) errCh := make(chan error, len(c.collectors)) - errs := make([]error, 0, len(c.collectors)) for _, collector := range c.collectors { go func() { @@ -226,7 +226,20 @@ func (c *Collection) Build(logger *slog.Logger) error { close(errCh) + var errs []error + for err := range errCh { + if errors.Is(err, perfdata.ErrNoData) || + errors.Is(err, perfdata.NewPdhError(perfdata.PdhCstatusNoObject)) || + errors.Is(err, perfdata.NewPdhError(perfdata.PdhCstatusNoCounter)) || + errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE) { + logger.Warn("couldn't initialize collector", + slog.Any("err", err), + ) + + continue + } + errs = append(errs, err) } diff --git a/pkg/public/error.go b/pkg/public/error.go deleted file mode 100644 index 1e65979f9..000000000 --- a/pkg/public/error.go +++ /dev/null @@ -1,22 +0,0 @@ -package public - -import ( - "errors" - - "github.com/prometheus-community/windows_exporter/internal/mi" - "github.com/prometheus-community/windows_exporter/internal/perfdata" -) - -var ( - ErrCollectorNotInitialized = errors.New("collector not initialized") - ErrNoData = errors.New("no data") -) - -var ( - // ErrsBuildCanIgnored indicates errors that can be ignored during build. - // This is used to allow end users to enable collectors that are available on all systems, e.g. mssql. - ErrsBuildCanIgnored = []error{ - perfdata.ErrNoData, - mi.MI_RESULT_INVALID_NAMESPACE, - } -)