process: Use registry collector for V1 data (#1814)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2024-12-21 22:58:47 +01:00
committed by GitHub
parent 39c929eefe
commit a9f8b3b722
158 changed files with 7793 additions and 7748 deletions

View File

@@ -1,53 +0,0 @@
// Copyright 2024 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package memory
const (
availableBytes = "Available Bytes"
availableKBytes = "Available KBytes"
availableMBytes = "Available MBytes"
cacheBytes = "Cache Bytes"
cacheBytesPeak = "Cache Bytes Peak"
cacheFaultsPerSec = "Cache Faults/sec"
commitLimit = "Commit Limit"
committedBytes = "Committed Bytes"
demandZeroFaultsPerSec = "Demand Zero Faults/sec"
freeAndZeroPageListBytes = "Free & Zero Page List Bytes"
freeSystemPageTableEntries = "Free System Page Table Entries"
modifiedPageListBytes = "Modified Page List Bytes"
pageFaultsPerSec = "Page Faults/sec"
pageReadsPerSec = "Page Reads/sec"
pagesInputPerSec = "Pages Input/sec"
pagesOutputPerSec = "Pages Output/sec"
pagesPerSec = "Pages/sec"
pageWritesPerSec = "Page Writes/sec"
poolNonpagedAllocs = "Pool Nonpaged Allocs"
poolNonpagedBytes = "Pool Nonpaged Bytes"
poolPagedAllocs = "Pool Paged Allocs"
poolPagedBytes = "Pool Paged Bytes"
poolPagedResidentBytes = "Pool Paged Resident Bytes"
standbyCacheCoreBytes = "Standby Cache Core Bytes"
standbyCacheNormalPriorityBytes = "Standby Cache Normal Priority Bytes"
standbyCacheReserveBytes = "Standby Cache Reserve Bytes"
systemCacheResidentBytes = "System Cache Resident Bytes"
systemCodeResidentBytes = "System Code Resident Bytes"
systemCodeTotalBytes = "System Code Total Bytes"
systemDriverResidentBytes = "System Driver Resident Bytes"
systemDriverTotalBytes = "System Driver Total Bytes"
transitionFaultsPerSec = "Transition Faults/sec"
transitionPagesRePurposedPerSec = "Transition Pages RePurposed/sec"
writeCopiesPerSec = "Write Copies/sec"
)

View File

@@ -26,7 +26,7 @@ import (
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/internal/headers/sysinfoapi"
"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"
)
@@ -42,7 +42,8 @@ var ConfigDefaults = Config{}
type Collector struct {
config Config
perfDataCollector *perfdata.Collector
perfDataCollector *pdh.Collector
perfDataObject []perfDataCounterValues
// Performance metrics
availableBytes *prometheus.Desc
@@ -109,46 +110,9 @@ func (c *Collector) Close() error {
}
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
counters := []string{
availableBytes,
availableKBytes,
availableMBytes,
cacheBytes,
cacheBytesPeak,
cacheFaultsPerSec,
commitLimit,
committedBytes,
demandZeroFaultsPerSec,
freeAndZeroPageListBytes,
freeSystemPageTableEntries,
modifiedPageListBytes,
pageFaultsPerSec,
pageReadsPerSec,
pagesInputPerSec,
pagesOutputPerSec,
pagesPerSec,
pageWritesPerSec,
poolNonpagedAllocs,
poolNonpagedBytes,
poolPagedAllocs,
poolPagedBytes,
poolPagedResidentBytes,
standbyCacheCoreBytes,
standbyCacheNormalPriorityBytes,
standbyCacheReserveBytes,
systemCacheResidentBytes,
systemCodeResidentBytes,
systemCodeTotalBytes,
systemDriverResidentBytes,
systemDriverTotalBytes,
transitionFaultsPerSec,
transitionPagesRePurposedPerSec,
writeCopiesPerSec,
}
var err error
c.perfDataCollector, err = perfdata.NewCollector("Memory", perfdata.InstancesAll, counters)
c.perfDataCollector, err = pdh.NewCollector[perfDataCounterValues]("Memory", pdh.InstancesAll)
if err != nil {
return fmt.Errorf("failed to create Memory collector: %w", err)
}
@@ -423,207 +387,201 @@ func (c *Collector) collectGlobalMemoryStatus(ch chan<- prometheus.Metric) error
}
func (c *Collector) collectPDH(ch chan<- prometheus.Metric) error {
perfData, err := c.perfDataCollector.Collect()
err := c.perfDataCollector.Collect(&c.perfDataObject)
if err != nil {
return fmt.Errorf("failed to collect Memory metrics: %w", err)
}
data, ok := perfData[perfdata.InstanceEmpty]
if !ok {
return fmt.Errorf("failed to collect Memory metrics: %w", types.ErrNoData)
}
ch <- prometheus.MustNewConstMetric(
c.availableBytes,
prometheus.GaugeValue,
data[availableBytes].FirstValue,
c.perfDataObject[0].AvailableBytes,
)
ch <- prometheus.MustNewConstMetric(
c.cacheBytes,
prometheus.GaugeValue,
data[cacheBytes].FirstValue,
c.perfDataObject[0].CacheBytes,
)
ch <- prometheus.MustNewConstMetric(
c.cacheBytesPeak,
prometheus.GaugeValue,
data[cacheBytesPeak].FirstValue,
c.perfDataObject[0].CacheBytesPeak,
)
ch <- prometheus.MustNewConstMetric(
c.cacheFaultsTotal,
prometheus.CounterValue,
data[cacheFaultsPerSec].FirstValue,
c.perfDataObject[0].CacheFaultsPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.commitLimit,
prometheus.GaugeValue,
data[commitLimit].FirstValue,
c.perfDataObject[0].CommitLimit,
)
ch <- prometheus.MustNewConstMetric(
c.committedBytes,
prometheus.GaugeValue,
data[committedBytes].FirstValue,
c.perfDataObject[0].CommittedBytes,
)
ch <- prometheus.MustNewConstMetric(
c.demandZeroFaultsTotal,
prometheus.CounterValue,
data[demandZeroFaultsPerSec].FirstValue,
c.perfDataObject[0].DemandZeroFaultsPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.freeAndZeroPageListBytes,
prometheus.GaugeValue,
data[freeAndZeroPageListBytes].FirstValue,
c.perfDataObject[0].FreeAndZeroPageListBytes,
)
ch <- prometheus.MustNewConstMetric(
c.freeSystemPageTableEntries,
prometheus.GaugeValue,
data[freeSystemPageTableEntries].FirstValue,
c.perfDataObject[0].FreeSystemPageTableEntries,
)
ch <- prometheus.MustNewConstMetric(
c.modifiedPageListBytes,
prometheus.GaugeValue,
data[modifiedPageListBytes].FirstValue,
c.perfDataObject[0].ModifiedPageListBytes,
)
ch <- prometheus.MustNewConstMetric(
c.pageFaultsTotal,
prometheus.CounterValue,
data[pageFaultsPerSec].FirstValue,
c.perfDataObject[0].PageFaultsPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.swapPageReadsTotal,
prometheus.CounterValue,
data[pageReadsPerSec].FirstValue,
c.perfDataObject[0].PageReadsPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.swapPagesReadTotal,
prometheus.CounterValue,
data[pagesInputPerSec].FirstValue,
c.perfDataObject[0].PagesInputPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.swapPagesWrittenTotal,
prometheus.CounterValue,
data[pagesOutputPerSec].FirstValue,
c.perfDataObject[0].PagesOutputPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.swapPageOperationsTotal,
prometheus.CounterValue,
data[pagesPerSec].FirstValue,
c.perfDataObject[0].PagesPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.swapPageWritesTotal,
prometheus.CounterValue,
data[pageWritesPerSec].FirstValue,
c.perfDataObject[0].PageWritesPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.poolNonPagedAllocationsTotal,
prometheus.GaugeValue,
data[poolNonpagedAllocs].FirstValue,
c.perfDataObject[0].PoolNonpagedAllocs,
)
ch <- prometheus.MustNewConstMetric(
c.poolNonPagedBytes,
prometheus.GaugeValue,
data[poolNonpagedBytes].FirstValue,
c.perfDataObject[0].PoolNonpagedBytes,
)
ch <- prometheus.MustNewConstMetric(
c.poolPagedAllocationsTotal,
prometheus.CounterValue,
data[poolPagedAllocs].FirstValue,
c.perfDataObject[0].PoolPagedAllocs,
)
ch <- prometheus.MustNewConstMetric(
c.poolPagedBytes,
prometheus.GaugeValue,
data[poolPagedBytes].FirstValue,
c.perfDataObject[0].PoolPagedBytes,
)
ch <- prometheus.MustNewConstMetric(
c.poolPagedResidentBytes,
prometheus.GaugeValue,
data[poolPagedResidentBytes].FirstValue,
c.perfDataObject[0].PoolPagedResidentBytes,
)
ch <- prometheus.MustNewConstMetric(
c.standbyCacheCoreBytes,
prometheus.GaugeValue,
data[standbyCacheCoreBytes].FirstValue,
c.perfDataObject[0].StandbyCacheCoreBytes,
)
ch <- prometheus.MustNewConstMetric(
c.standbyCacheNormalPriorityBytes,
prometheus.GaugeValue,
data[standbyCacheNormalPriorityBytes].FirstValue,
c.perfDataObject[0].StandbyCacheNormalPriorityBytes,
)
ch <- prometheus.MustNewConstMetric(
c.standbyCacheReserveBytes,
prometheus.GaugeValue,
data[standbyCacheReserveBytes].FirstValue,
c.perfDataObject[0].StandbyCacheReserveBytes,
)
ch <- prometheus.MustNewConstMetric(
c.systemCacheResidentBytes,
prometheus.GaugeValue,
data[systemCacheResidentBytes].FirstValue,
c.perfDataObject[0].SystemCacheResidentBytes,
)
ch <- prometheus.MustNewConstMetric(
c.systemCodeResidentBytes,
prometheus.GaugeValue,
data[systemCodeResidentBytes].FirstValue,
c.perfDataObject[0].SystemCodeResidentBytes,
)
ch <- prometheus.MustNewConstMetric(
c.systemCodeTotalBytes,
prometheus.GaugeValue,
data[systemCodeTotalBytes].FirstValue,
c.perfDataObject[0].SystemCodeTotalBytes,
)
ch <- prometheus.MustNewConstMetric(
c.systemDriverResidentBytes,
prometheus.GaugeValue,
data[systemDriverResidentBytes].FirstValue,
c.perfDataObject[0].SystemDriverResidentBytes,
)
ch <- prometheus.MustNewConstMetric(
c.systemDriverTotalBytes,
prometheus.GaugeValue,
data[systemDriverTotalBytes].FirstValue,
c.perfDataObject[0].SystemDriverTotalBytes,
)
ch <- prometheus.MustNewConstMetric(
c.transitionFaultsTotal,
prometheus.CounterValue,
data[transitionFaultsPerSec].FirstValue,
c.perfDataObject[0].TransitionFaultsPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.transitionPagesRepurposedTotal,
prometheus.CounterValue,
data[transitionPagesRePurposedPerSec].FirstValue,
c.perfDataObject[0].TransitionPagesRePurposedPerSec,
)
ch <- prometheus.MustNewConstMetric(
c.writeCopiesTotal,
prometheus.CounterValue,
data[writeCopiesPerSec].FirstValue,
c.perfDataObject[0].WriteCopiesPerSec,
)
return nil

View File

@@ -0,0 +1,53 @@
// Copyright 2024 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package memory
type perfDataCounterValues struct {
AvailableBytes float64 `perfdata:"Available Bytes"`
AvailableKBytes float64 `perfdata:"Available KBytes"`
AvailableMBytes float64 `perfdata:"Available MBytes"`
CacheBytes float64 `perfdata:"Cache Bytes"`
CacheBytesPeak float64 `perfdata:"Cache Bytes Peak"`
CacheFaultsPerSec float64 `perfdata:"Cache Faults/sec"`
CommitLimit float64 `perfdata:"Commit Limit"`
CommittedBytes float64 `perfdata:"Committed Bytes"`
DemandZeroFaultsPerSec float64 `perfdata:"Demand Zero Faults/sec"`
FreeAndZeroPageListBytes float64 `perfdata:"Free & Zero Page List Bytes"`
FreeSystemPageTableEntries float64 `perfdata:"Free System Page Table Entries"`
ModifiedPageListBytes float64 `perfdata:"Modified Page List Bytes"`
PageFaultsPerSec float64 `perfdata:"Page Faults/sec"`
PageReadsPerSec float64 `perfdata:"Page Reads/sec"`
PagesInputPerSec float64 `perfdata:"Pages Input/sec"`
PagesOutputPerSec float64 `perfdata:"Pages Output/sec"`
PagesPerSec float64 `perfdata:"Pages/sec"`
PageWritesPerSec float64 `perfdata:"Page Writes/sec"`
PoolNonpagedAllocs float64 `perfdata:"Pool Nonpaged Allocs"`
PoolNonpagedBytes float64 `perfdata:"Pool Nonpaged Bytes"`
PoolPagedAllocs float64 `perfdata:"Pool Paged Allocs"`
PoolPagedBytes float64 `perfdata:"Pool Paged Bytes"`
PoolPagedResidentBytes float64 `perfdata:"Pool Paged Resident Bytes"`
StandbyCacheCoreBytes float64 `perfdata:"Standby Cache Core Bytes"`
StandbyCacheNormalPriorityBytes float64 `perfdata:"Standby Cache Normal Priority Bytes"`
StandbyCacheReserveBytes float64 `perfdata:"Standby Cache Reserve Bytes"`
SystemCacheResidentBytes float64 `perfdata:"System Cache Resident Bytes"`
SystemCodeResidentBytes float64 `perfdata:"System Code Resident Bytes"`
SystemCodeTotalBytes float64 `perfdata:"System Code Total Bytes"`
SystemDriverResidentBytes float64 `perfdata:"System Driver Resident Bytes"`
SystemDriverTotalBytes float64 `perfdata:"System Driver Total Bytes"`
TransitionFaultsPerSec float64 `perfdata:"Transition Faults/sec"`
TransitionPagesRePurposedPerSec float64 `perfdata:"Transition Pages RePurposed/sec"`
WriteCopiesPerSec float64 `perfdata:"Write Copies/sec"`
}