From ebabddf55843ab97a4f5e17410541b45171660fb Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Wed, 16 Mar 2022 13:20:19 +1000 Subject: [PATCH] Continue OS collector on absent paging file Inactive or missing paging file should not be cause for OS collector to fail. Instead, log the error and continue with OS collection. Signed-off-by: Ben Reedy --- collector/os.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/collector/os.go b/collector/os.go index 27780b2f..571d0cba 100644 --- a/collector/os.go +++ b/collector/os.go @@ -179,11 +179,7 @@ func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) ( if err != nil { return nil, err } - pagingFiles, _, err := memManKey.GetStringsValue("ExistingPageFiles") - if err != nil { - return nil, err - } - + pagingFiles, _, pagingErr := memManKey.GetStringsValue("ExistingPageFiles") // Get build number and product name from registry ntKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) defer ntKey.Close() @@ -261,12 +257,21 @@ func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) ( timezoneName, ) - ch <- prometheus.MustNewConstMetric( - c.PagingFreeBytes, - prometheus.GaugeValue, - pfb, - ) + if pagingErr == nil { + ch <- prometheus.MustNewConstMetric( + c.PagingFreeBytes, + prometheus.GaugeValue, + pfb, + ) + ch <- prometheus.MustNewConstMetric( + c.PagingLimitBytes, + prometheus.GaugeValue, + fsipf, + ) + } else { + log.Debugln("Could not find HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management key. windows_os_paging_free_bytes and windows_os_paging_limit_bytes will be omitted.") + } ch <- prometheus.MustNewConstMetric( c.VirtualMemoryFreeBytes, prometheus.GaugeValue, @@ -300,12 +305,6 @@ func (c *OSCollector) collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) ( float64(nwgi.LoggedOnUsers), ) - ch <- prometheus.MustNewConstMetric( - c.PagingLimitBytes, - prometheus.GaugeValue, - fsipf, - ) - ch <- prometheus.MustNewConstMetric( c.VirtualMemoryBytes, prometheus.GaugeValue,