chore: Remove registry based perfdata collector (#1742)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2024-11-17 21:51:12 +01:00
committed by GitHub
parent 6206b695c6
commit e6a15d4ec4
213 changed files with 8079 additions and 12405 deletions

View File

@@ -1,3 +1,5 @@
//go:build windows
package physical_disk
const (

View File

@@ -11,7 +11,6 @@ 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/perfdata/perftypes"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus/client_golang/prometheus"
)
@@ -32,7 +31,7 @@ var ConfigDefaults = Config{
type Collector struct {
config Config
perfDataCollector perfdata.Collector
perfDataCollector *perfdata.Collector
idleTime *prometheus.Desc
readBytesTotal *prometheus.Desc
@@ -108,11 +107,7 @@ func (c *Collector) GetName() string {
return Name
}
func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
return []string{}, nil
}
func (c *Collector) Close(_ *slog.Logger) error {
func (c *Collector) Close() error {
return nil
}
@@ -134,7 +129,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
var err error
c.perfDataCollector, err = perfdata.NewCollector(perfdata.V2, "PhysicalDisk", perfdata.AllInstances, counters)
c.perfDataCollector, err = perfdata.NewCollector("PhysicalDisk", perfdata.InstanceAll, counters)
if err != nil {
return fmt.Errorf("failed to create PhysicalDisk collector: %w", err)
}
@@ -228,15 +223,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *Collector) Collect(_ *types.ScrapeContext, _ *slog.Logger, ch chan<- prometheus.Metric) error {
if err := c.collect(ch); err != nil {
return fmt.Errorf("failed collecting physical_disk metrics: %w", err)
}
return nil
}
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
perfData, err := c.perfDataCollector.Collect()
if err != nil {
return fmt.Errorf("failed to collect PhysicalDisk metrics: %w", err)
@@ -318,21 +305,21 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric(
c.readLatency,
prometheus.CounterValue,
disk[AvgDiskSecPerRead].FirstValue*perftypes.TicksToSecondScaleFactor,
disk[AvgDiskSecPerRead].FirstValue*perfdata.TicksToSecondScaleFactor,
disk_number,
)
ch <- prometheus.MustNewConstMetric(
c.writeLatency,
prometheus.CounterValue,
disk[AvgDiskSecPerWrite].FirstValue*perftypes.TicksToSecondScaleFactor,
disk[AvgDiskSecPerWrite].FirstValue*perfdata.TicksToSecondScaleFactor,
disk_number,
)
ch <- prometheus.MustNewConstMetric(
c.readWriteLatency,
prometheus.CounterValue,
disk[AvgDiskSecPerTransfer].FirstValue*perftypes.TicksToSecondScaleFactor,
disk[AvgDiskSecPerTransfer].FirstValue*perfdata.TicksToSecondScaleFactor,
disk_number,
)
}

View File

@@ -1,11 +1,13 @@
//go:build windows
package physical_disk_test
import (
"testing"
"github.com/prometheus-community/windows_exporter/internal/collector/physical_disk"
"github.com/prometheus-community/windows_exporter/internal/testutils"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus-community/windows_exporter/internal/utils/testutils"
)
func BenchmarkCollector(b *testing.B) {