Skip to content

Commit

Permalink
remote_fx: refactor collector (#1738)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Nov 15, 2024
1 parent a4ec0a9 commit 78bd720
Show file tree
Hide file tree
Showing 32 changed files with 278 additions and 204 deletions.
7 changes: 6 additions & 1 deletion internal/collector/ad/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/internal/mi"
"github.com/prometheus-community/windows_exporter/internal/perfdata"
"github.com/prometheus-community/windows_exporter/internal/toggle"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -115,6 +116,10 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

Expand Down Expand Up @@ -268,7 +273,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "DirectoryServices", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "DirectoryServices", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create DirectoryServices collector: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/collector/adcs/adcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

Expand All @@ -95,7 +99,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "Certification Authority", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "Certification Authority", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create Certification Authority collector: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/collector/adfs/adfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

Expand Down Expand Up @@ -157,7 +161,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "AD FS", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "AD FS", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create AD FS collector: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/collector/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

Expand Down Expand Up @@ -128,7 +132,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "Cache", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "Cache", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create Cache collector: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/collector/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

Expand Down
20 changes: 17 additions & 3 deletions internal/collector/dfsr/dfsr.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
if slices.Contains(c.config.CollectorsEnabled, "connection") {
c.perfDataCollectorConnection.Close()
}

if slices.Contains(c.config.CollectorsEnabled, "folder") {
c.perfDataCollectorFolder.Close()
}

if slices.Contains(c.config.CollectorsEnabled, "volume") {
c.perfDataCollectorVolume.Close()
}
}

return nil
}

Expand All @@ -189,7 +203,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
sizeOfFilesReceivedTotal,
}

c.perfDataCollectorConnection, err = perfdata.NewCollector(perfdata.V1, "DFS Replication Connections", perfdata.AllInstances, counters)
c.perfDataCollectorConnection, err = perfdata.NewCollector(perfdata.V2, "DFS Replication Connections", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create DFS Replication Connections collector: %w", err)
}
Expand Down Expand Up @@ -226,7 +240,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
updatesDroppedTotal,
}

c.perfDataCollectorFolder, err = perfdata.NewCollector(perfdata.V1, "DFS Replicated Folders", perfdata.AllInstances, counters)
c.perfDataCollectorFolder, err = perfdata.NewCollector(perfdata.V2, "DFS Replicated Folders", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create DFS Replicated Folders collector: %w", err)
}
Expand All @@ -241,7 +255,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
usnJournalUnreadPercentage,
}

c.perfDataCollectorVolume, err = perfdata.NewCollector(perfdata.V1, "DFS Replication Service Volumes", perfdata.AllInstances, counters)
c.perfDataCollectorVolume, err = perfdata.NewCollector(perfdata.V2, "DFS Replication Service Volumes", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create DFS Replication Service Volumes collector: %w", err)
}
Expand Down
14 changes: 8 additions & 6 deletions internal/collector/dhcp/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
if toggle.IsPDHEnabled() {
counters := []string{
var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "DHCP Server", perfdata.AllInstances, []string{
acksTotal,
activeQueueLength,
conflictCheckQueueLength,
Expand All @@ -116,11 +122,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
packetsReceivedTotal,
releasesTotal,
requestsTotal,
}

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "DHCP Server", perfdata.AllInstances, counters)
})
if err != nil {
return fmt.Errorf("failed to create DHCP Server collector: %w", err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/collector/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
c.perfDataCollector.Close()

return nil
}

func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
counters := []string{
var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "DNS", perfdata.AllInstances, []string{
axfrRequestReceived,
axfrRequestSent,
axfrResponseReceived,
Expand Down Expand Up @@ -121,11 +125,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
winsReverseResponseSent,
zoneTransferFailure,
zoneTransferSOARequestSent,
}

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "DNS", perfdata.AllInstances, counters)
})
if err != nil {
return fmt.Errorf("failed to create DNS collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_active_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *Collector) buildActiveSync() error {

var err error

c.perfDataCollectorActiveSync, err = perfdata.NewCollector(perfdata.V1, "MSExchange ActiveSync", perfdata.AllInstances, counters)
c.perfDataCollectorActiveSync, err = perfdata.NewCollector(perfdata.V2, "MSExchange ActiveSync", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange ActiveSync collector: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Collector) buildADAccessProcesses() error {

var err error

c.perfDataCollectorADAccessProcesses, err = perfdata.NewCollector(perfdata.V1, "MSExchange ADAccess Processes", perfdata.AllInstances, counters)
c.perfDataCollectorADAccessProcesses, err = perfdata.NewCollector(perfdata.V2, "MSExchange ADAccess Processes", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange ADAccess Processes collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *Collector) buildAutoDiscover() error {

var err error

c.perfDataCollectorAutoDiscover, err = perfdata.NewCollector(perfdata.V1, "MSExchange Autodiscover", perfdata.AllInstances, counters)
c.perfDataCollectorAutoDiscover, err = perfdata.NewCollector(perfdata.V2, "MSExchange Autodiscover", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange Autodiscover collector: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (c *Collector) buildAvailabilityService() error {

var err error

c.perfDataCollectorAvailabilityService, err = perfdata.NewCollector(perfdata.V1, "MSExchange Availability Service", perfdata.AllInstances, counters)
c.perfDataCollectorAvailabilityService, err = perfdata.NewCollector(perfdata.V2, "MSExchange Availability Service", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange Availability Service collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *Collector) buildHTTPProxy() error {

var err error

c.perfDataCollectorHttpProxy, err = perfdata.NewCollector(perfdata.V1, "MSExchange HttpProxy", perfdata.AllInstances, counters)
c.perfDataCollectorHttpProxy, err = perfdata.NewCollector(perfdata.V2, "MSExchange HttpProxy", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange HttpProxy collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_mapi_http_emsmdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *Collector) buildMapiHttpEmsmdb() error {

var err error

c.perfDataCollectorMapiHttpEmsmdb, err = perfdata.NewCollector(perfdata.V1, "MSExchange MapiHttp Emsmdb", perfdata.AllInstances, counters)
c.perfDataCollectorMapiHttpEmsmdb, err = perfdata.NewCollector(perfdata.V2, "MSExchange MapiHttp Emsmdb", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange MapiHttp Emsmdb: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_outlook_web_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *Collector) buildOWA() error {

var err error

c.perfDataCollectorOWA, err = perfdata.NewCollector(perfdata.V1, "MSExchange OWA", perfdata.AllInstances, counters)
c.perfDataCollectorOWA, err = perfdata.NewCollector(perfdata.V2, "MSExchange OWA", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange OWA collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_rpc_client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Collector) buildRPC() error {

var err error

c.perfDataCollectorRpcClientAccess, err = perfdata.NewCollector(perfdata.V1, "MSExchange RpcClientAccess", perfdata.AllInstances, counters)
c.perfDataCollectorRpcClientAccess, err = perfdata.NewCollector(perfdata.V2, "MSExchange RpcClientAccess", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange RpcClientAccess collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/exchange/exchange_transport_queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *Collector) buildTransportQueues() error {

var err error

c.perfDataCollectorTransportQueues, err = perfdata.NewCollector(perfdata.V1, "MSExchangeTransport Queues", perfdata.AllInstances, counters)
c.perfDataCollectorTransportQueues, err = perfdata.NewCollector(perfdata.V2, "MSExchangeTransport Queues", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchangeTransport Queues collector: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Collector) buildWorkloadManagementWorkloads() error {

var err error

c.perfDataCollectorWorkloadManagementWorkloads, err = perfdata.NewCollector(perfdata.V1, "MSExchange WorkloadManagement Workloads", perfdata.AllInstances, counters)
c.perfDataCollectorWorkloadManagementWorkloads, err = perfdata.NewCollector(perfdata.V2, "MSExchange WorkloadManagement Workloads", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create MSExchange WorkloadManagement Workloads collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/logical_disk/logical_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "LogicalDisk", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "LogicalDisk", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create LogicalDisk collector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "Memory", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "Memory", perfdata.AllInstances, counters)
if err != nil {
return fmt.Errorf("failed to create LogicalDisk collector: %w", err)
}
Expand Down
14 changes: 8 additions & 6 deletions internal/collector/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,18 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
if toggle.IsPDHEnabled() {
counters := []string{
var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "Network Interface", perfdata.AllInstances, []string{
BytesReceivedPerSec,
BytesSentPerSec,
BytesTotalPerSec,
Expand All @@ -165,11 +171,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
PacketsReceivedUnknown,
PacketsSentPerSec,
CurrentBandwidth,
}

var err error

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "Network Interface", perfdata.AllInstances, counters)
})
if err != nil {
return fmt.Errorf("failed to create Processor Information collector: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/collector/pagefile/pagefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
c.perfDataCollector.Close()

return nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/collector/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
}

func (c *Collector) Close(_ *slog.Logger) error {
if toggle.IsPDHEnabled() {
c.perfDataCollector.Close()
}

return nil
}

Expand Down Expand Up @@ -194,7 +198,7 @@ func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
if errors.Is(err, v2.NewPdhError(v2.PdhCstatusNoObject)) {
counters[0] = idProcess

c.perfDataCollector, err = perfdata.NewCollector(perfdata.V1, "Process", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "Process", perfdata.AllInstances, counters)
}

if err != nil {
Expand Down
Loading

0 comments on commit 78bd720

Please sign in to comment.