memory: publish pool allocation counts as gauges (#2721)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-15 17:58:18 +00:00
committed by GitHub
parent 94b0eff655
commit 8fe85c143b
5 changed files with 30 additions and 18 deletions
+11 -11
View File
@@ -64,9 +64,9 @@ type Collector struct {
swapPagesWrittenTotal *prometheus.Desc
swapPageOperationsTotal *prometheus.Desc
swapPageWritesTotal *prometheus.Desc
poolNonPagedAllocationsTotal *prometheus.Desc
poolNonPagedAllocations *prometheus.Desc
poolNonPagedBytes *prometheus.Desc
poolPagedAllocationsTotal *prometheus.Desc
poolPagedAllocations *prometheus.Desc
poolPagedBytes *prometheus.Desc
poolPagedResidentBytes *prometheus.Desc
standbyCacheCoreBytes *prometheus.Desc
@@ -210,9 +210,9 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
nil,
nil,
)
c.poolNonPagedAllocationsTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "pool_nonpaged_allocs_total"),
"The number of calls to allocate space in the nonpaged pool. The nonpaged pool is an area of system memory area for objects that cannot be written"+
c.poolNonPagedAllocations = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "pool_nonpaged_allocs"),
"Number of allocations in the nonpaged pool, regardless of their size. The nonpaged pool is an area of system memory for objects that cannot be written"+
" to disk, and must remain in physical memory as long as they are allocated (PoolNonpagedAllocs)",
nil,
nil,
@@ -224,9 +224,9 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
nil,
nil,
)
c.poolPagedAllocationsTotal = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_allocs_total"),
"Number of calls to allocate space in the paged pool, regardless of the amount of space allocated in each call (PoolPagedAllocs)",
c.poolPagedAllocations = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "pool_paged_allocs"),
"Number of allocations in the paged pool, regardless of their size (PoolPagedAllocs)",
nil,
nil,
)
@@ -491,7 +491,7 @@ func (c *Collector) collectPDH(ch chan<- prometheus.Metric) error {
)
ch <- prometheus.MustNewConstMetric(
c.poolNonPagedAllocationsTotal,
c.poolNonPagedAllocations,
prometheus.GaugeValue,
c.perfDataObject[0].PoolNonpagedAllocs,
)
@@ -503,8 +503,8 @@ func (c *Collector) collectPDH(ch chan<- prometheus.Metric) error {
)
ch <- prometheus.MustNewConstMetric(
c.poolPagedAllocationsTotal,
prometheus.CounterValue,
c.poolPagedAllocations,
prometheus.GaugeValue,
c.perfDataObject[0].PoolPagedAllocs,
)
+11 -1
View File
@@ -22,6 +22,8 @@ import (
"github.com/prometheus-community/windows_exporter/internal/collector/memory"
"github.com/prometheus-community/windows_exporter/internal/utils/testutils"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/require"
)
func BenchmarkCollector(b *testing.B) {
@@ -29,5 +31,13 @@ func BenchmarkCollector(b *testing.B) {
}
func TestCollector(t *testing.T) {
testutils.TestCollector(t, memory.New, nil)
families := testutils.TestCollector(t, memory.New, nil)
// "Pool Paged Allocs" and "Pool Nonpaged Allocs" are PERF_COUNTER_RAWCOUNT,
// an instantaneous value.
for _, name := range []string{"windows_memory_pool_paged_allocs", "windows_memory_pool_nonpaged_allocs"} {
require.Contains(t, families, name)
require.Equal(t, dto.MetricType_GAUGE, families[name].GetType(), name)
require.NotContains(t, families, name+"_total")
}
}