mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-09 20:16:35 +00:00
process: Use registry collector for V1 data (#1814)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/psapi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/pdh"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@@ -40,7 +40,8 @@ var ConfigDefaults = Config{}
|
||||
type Collector struct {
|
||||
config Config
|
||||
|
||||
perfDataCollector *perfdata.Collector
|
||||
perfDataCollector *pdh.Collector
|
||||
perfDataObject []perfDataCounterValues
|
||||
|
||||
pagingFreeBytes *prometheus.Desc
|
||||
pagingLimitBytes *prometheus.Desc
|
||||
@@ -75,9 +76,7 @@ func (c *Collector) Close() error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
var err error
|
||||
|
||||
c.perfDataCollector, err = perfdata.NewCollector("Paging File", perfdata.InstancesAll, []string{
|
||||
usage,
|
||||
})
|
||||
c.perfDataCollector, err = pdh.NewCollector[perfDataCounterValues]("Paging File", pdh.InstancesAll)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create Paging File collector: %w", err)
|
||||
}
|
||||
@@ -102,7 +101,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(ch chan<- prometheus.Metric) error {
|
||||
data, err := c.perfDataCollector.Collect()
|
||||
err := c.perfDataCollector.Collect(&c.perfDataObject)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to collect Paging File metrics: %w", err)
|
||||
}
|
||||
@@ -112,8 +111,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
||||
return err
|
||||
}
|
||||
|
||||
for fileName, pageFile := range data {
|
||||
fileString := strings.ReplaceAll(fileName, `\??\`, "")
|
||||
for _, data := range c.perfDataObject {
|
||||
fileString := strings.ReplaceAll(data.Name, `\??\`, "")
|
||||
file, err := os.Stat(fileString)
|
||||
|
||||
var fileSize float64
|
||||
@@ -126,7 +125,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.pagingFreeBytes,
|
||||
prometheus.GaugeValue,
|
||||
fileSize-(pageFile[usage].FirstValue*float64(gpi.PageSize)),
|
||||
fileSize-(data.Usage*float64(gpi.PageSize)),
|
||||
fileString,
|
||||
)
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
package pagefile
|
||||
|
||||
const (
|
||||
usage = "% Usage"
|
||||
)
|
||||
type perfDataCounterValues struct {
|
||||
Name string
|
||||
|
||||
Usage float64 `perfdata:"% Usage"`
|
||||
}
|
||||
Reference in New Issue
Block a user