From 8fe85c143b6550f23be3e7254616f474c10d6c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Thu, 15 Oct 2026 19:58:18 +0200 Subject: [PATCH] memory: publish pool allocation counts as gauges (#2721) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- UPGRADE.md | 2 ++ docs/collector.memory.md | 4 ++-- internal/collector/memory/memory.go | 22 +++++++++++----------- internal/collector/memory/memory_test.go | 12 +++++++++++- tools/e2e-output.txt | 8 ++++---- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 899e61ca..83f9d9c4 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -215,6 +215,8 @@ Renamed: | `windows_hyperv_virtual_storage_device_throughput` | `windows_hyperv_virtual_storage_device_throughput_total` | Now a counter, use `rate()` | | `windows_filetime_mtime_timestamp_seconds` | `windows_file_mtime_timestamp_seconds` | See [filetime](#filetime-collector-removed) | | `windows_memory_commit_limit` | `windows_memory_commit_limit_bytes` | Unit suffix added, same value | +| `windows_memory_pool_paged_allocs_total` | `windows_memory_pool_paged_allocs` | Now a gauge, query it without `rate()` | +| `windows_memory_pool_nonpaged_allocs_total` | `windows_memory_pool_nonpaged_allocs` | Same value and type (gauge) | | `windows_smb_server_shares_read_requests_count_total` | `windows_smb_server_shares_read_requests_total` | Same value | | `windows_smb_server_shares_write_requests_count_total` | `windows_smb_server_shares_write_requests_total` | Same value | | `windows_smb_server_shares_metadata_requests_count_total` | `windows_smb_server_shares_metadata_requests_total` | Same value | diff --git a/docs/collector.memory.md b/docs/collector.memory.md index 7c783b44..4a6ce8a2 100644 --- a/docs/collector.memory.md +++ b/docs/collector.memory.md @@ -34,9 +34,9 @@ None | `windows_memory_swap_page_writes_total` | Number of disk page writes (a single write operation writing several pages is still only counted once) | counter | None | | `windows_memory_physical_free_bytes` | Bytes of physical memory currently unused and available | gauge | None | | `windows_memory_physical_total_bytes` | Total bytes of physical memory available to the operating system. This value does not necessarily indicate the true amount of physical memory, but what is reported to the operating system as available to it | gauge | None | -| `windows_memory_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 to disk, and must remain in physical memory as long as they are allocated | gauge | None | +| `windows_memory_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 | gauge | None | | `windows_memory_pool_nonpaged_bytes` | Number of bytes in the non-paged pool, an area of the system virtual memory that is used for objects that cannot be written to disk, but must remain in physical memory as long as they are allocated | gauge | None | -| `windows_memory_pool_paged_allocs_total` | Number of calls to allocate space in the paged pool, regardless of the amount of space allocated in each call | counter | None | +| `windows_memory_pool_paged_allocs` | Number of allocations in the paged pool, regardless of their size | gauge | None | | `windows_memory_pool_paged_bytes` | Number of bytes in the paged pool | gauge | None | | `windows_memory_pool_paged_resident_bytes` | The size, in bytes, of the portion of the paged pool that is currently resident and active in physical memory. The paged pool is an area of the system virtual memory that is used for objects that can be written to disk when they are not being used | gauge | None | | `windows_memory_process_memory_limit_bytes` | Maximum number of bytes of memory that can be allocated to a process | gauge | None | diff --git a/internal/collector/memory/memory.go b/internal/collector/memory/memory.go index 37838d05..25aaed0d 100644 --- a/internal/collector/memory/memory.go +++ b/internal/collector/memory/memory.go @@ -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, ) diff --git a/internal/collector/memory/memory_test.go b/internal/collector/memory/memory_test.go index fb9d3d54..9b6bc2f5 100644 --- a/internal/collector/memory/memory_test.go +++ b/internal/collector/memory/memory_test.go @@ -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") + } } diff --git a/tools/e2e-output.txt b/tools/e2e-output.txt index c53cc9c9..a7813e87 100644 --- a/tools/e2e-output.txt +++ b/tools/e2e-output.txt @@ -201,12 +201,12 @@ windows_exporter_collector_timeout{collector="udp"} 0 # TYPE windows_memory_physical_free_bytes gauge # HELP windows_memory_physical_total_bytes The amount of actual physical memory, in bytes. # TYPE windows_memory_physical_total_bytes gauge -# HELP windows_memory_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 to disk, and must remain in physical memory as long as they are allocated (PoolNonpagedAllocs) -# TYPE windows_memory_pool_nonpaged_allocs_total gauge +# HELP windows_memory_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) +# TYPE windows_memory_pool_nonpaged_allocs gauge # HELP windows_memory_pool_nonpaged_bytes Number of bytes in the non-paged pool, an area of the system virtual memory that is used for objects that cannot be written to disk, but must remain in physical memory as long as they are allocated (PoolNonpagedBytes) # TYPE windows_memory_pool_nonpaged_bytes gauge -# HELP windows_memory_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) -# TYPE windows_memory_pool_paged_allocs_total counter +# HELP windows_memory_pool_paged_allocs Number of allocations in the paged pool, regardless of their size (PoolPagedAllocs) +# TYPE windows_memory_pool_paged_allocs gauge # HELP windows_memory_pool_paged_bytes (PoolPagedBytes) # TYPE windows_memory_pool_paged_bytes gauge # HELP windows_memory_pool_paged_resident_bytes The size, in bytes, of the portion of the paged pool that is currently resident and active in physical memory. The paged pool is an area of the system virtual memory that is used for objects that can be written to disk when they are not being used (PoolPagedResidentBytes)