Skip to content

Commit

Permalink
process: fix metric labels for multiple process instances
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Dec 9, 2024
1 parent dd9695b commit d68a164
Show file tree
Hide file tree
Showing 39 changed files with 70 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .run/all.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<configuration default="false" name="all" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="run">
<module name="windows_exporter" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="--web.listen-address=127.0.0.1:9182 --log.level=info --collectors.enabled=ad,adcs,adfs,cache,container,cpu,cpu_info,cs,dfsr,dhcp,diskdrive,dns,exchange,filetime,fsrmquota,hyperv,iis,license,logical_disk,logon,memory,mscluster,msmq,mssql,net,netframework,nps,os,pagefile,performancecounter,physical_disk,printer,process,remote_fx,scheduled_task,service,smb,smbclient,smtp,system,tcp,terminal_services,thermalzone,time,udp,update,vmware --debug.enabled" />
<parameters value="--web.listen-address=127.0.0.1:9182 --log.level=info --collectors.enabled=ad,adcs,adfs,cache,container,cpu,cpu_info,cs,dfsr,dhcp,diskdrive,dns,exchange,filetime,fsrmquota,hyperv,iis,license,logical_disk,logon,memory,mscluster,msmq,mssql,net,netframework,nps,os,pagefile,performancecounter,physical_disk,printer,process,remote_fx,scheduled_task,service,smb,smbclient,smtp,system,tcp,terminal_services,thermalzone,time,udp,update,vmware,performancecounter --debug.enabled --collector.performancecounter.objects='[{ &quot;name&quot;: &quot;memory&quot;, &quot;object&quot;: &quot;Memory&quot;, &quot;counters&quot;: [{ &quot;name&quot;:&quot;Cache Faults/sc&quot;, &quot;type&quot;:&quot;counter&quot; }]}]'" />
<sudo value="true" />
<kind value="PACKAGE" />
<package value="github.com/prometheus-community/windows_exporter/cmd/windows_exporter" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/exporter.go" />
<method v="2" />
</configuration>
</component>
</component>
25 changes: 8 additions & 17 deletions cmd/windows_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ package main
//goland:noinspection GoUnsortedImport
//nolint:gofumpt

Check failure on line 21 in cmd/windows_exporter/main.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:gofumpt` is unused for linter "gofumpt" (nolintlint)
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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/collector/ad/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/adcs/adcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions internal/collector/adfs/adfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions internal/collector/dfsr/dfsr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/dhcp/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_active_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_ad_access_processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_availability_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_mapi_http_emsmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_outlook_web_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_rpc_client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_transport_queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/exchange/exchange_workload_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/collector/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit d68a164

Please sign in to comment.