Fix naming

This commit is contained in:
Calle Pettersson
2018-11-18 18:19:18 +01:00
parent 8ef341a51c
commit 9e1d4bbaed

View File

@@ -9,33 +9,30 @@ import (
) )
func init() { func init() {
Factories["os_memory"] = NewOS_MemoryCollector Factories["memory"] = NewMemoryCollector
} }
// A OS_MemoryCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfOS_Memory metrics // A MemoryCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfOS_Memory metrics
type OS_MemoryCollector struct { type MemoryCollector struct {
AvailableBytes *prometheus.Desc AvailableBytes *prometheus.Desc
AvailableKBytes *prometheus.Desc
AvailableMBytes *prometheus.Desc
CacheBytes *prometheus.Desc CacheBytes *prometheus.Desc
CacheBytesPeak *prometheus.Desc CacheBytesPeak *prometheus.Desc
CacheFaultsPersec *prometheus.Desc CacheFaultsTotal *prometheus.Desc
CommitLimit *prometheus.Desc CommitLimit *prometheus.Desc
CommittedBytes *prometheus.Desc CommittedBytes *prometheus.Desc
DemandZeroFaultsPersec *prometheus.Desc DemandZeroFaultsTotal *prometheus.Desc
FreeAndZeroPageListBytes *prometheus.Desc FreeAndZeroPageListBytes *prometheus.Desc
FreeSystemPageTableEntries *prometheus.Desc FreeSystemPageTableEntries *prometheus.Desc
ModifiedPageListBytes *prometheus.Desc ModifiedPageListBytes *prometheus.Desc
PageFaultsPersec *prometheus.Desc PageFaultsTotal *prometheus.Desc
PageReadsPersec *prometheus.Desc SwapPageReadsTotal *prometheus.Desc
PagesInputPersec *prometheus.Desc SwapPagesReadTotal *prometheus.Desc
PagesOutputPersec *prometheus.Desc SwapPagesWrittenTotal *prometheus.Desc
PagesPersec *prometheus.Desc SwapPageOperationsTotal *prometheus.Desc
PageWritesPersec *prometheus.Desc SwapPageWritesTotal *prometheus.Desc
PercentCommittedBytesInUse *prometheus.Desc PoolNonpagedAllocsTotal *prometheus.Desc
PoolNonpagedAllocs *prometheus.Desc
PoolNonpagedBytes *prometheus.Desc PoolNonpagedBytes *prometheus.Desc
PoolPagedAllocs *prometheus.Desc PoolPagedAllocsTotal *prometheus.Desc
PoolPagedBytes *prometheus.Desc PoolPagedBytes *prometheus.Desc
PoolPagedResidentBytes *prometheus.Desc PoolPagedResidentBytes *prometheus.Desc
StandbyCacheCoreBytes *prometheus.Desc StandbyCacheCoreBytes *prometheus.Desc
@@ -46,31 +43,20 @@ type OS_MemoryCollector struct {
SystemCodeTotalBytes *prometheus.Desc SystemCodeTotalBytes *prometheus.Desc
SystemDriverResidentBytes *prometheus.Desc SystemDriverResidentBytes *prometheus.Desc
SystemDriverTotalBytes *prometheus.Desc SystemDriverTotalBytes *prometheus.Desc
TransitionFaultsPersec *prometheus.Desc TransitionFaultsTotal *prometheus.Desc
TransitionPagesRePurposedPersec *prometheus.Desc TransitionPagesRepurposedTotal *prometheus.Desc
WriteCopiesPersec *prometheus.Desc WriteCopiesTotal *prometheus.Desc
} }
// NewOS_MemoryCollector ... // NewMemoryCollector ...
func NewOS_MemoryCollector() (Collector, error) { func NewMemoryCollector() (Collector, error) {
const subsystem = "os_memory" const subsystem = "memory"
return &OS_MemoryCollector{ return &MemoryCollector{
AvailableBytes: prometheus.NewDesc( AvailableBytes: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "available_bytes"), prometheus.BuildFQName(Namespace, subsystem, "available_bytes"),
"(AvailableBytes)", "The amount of physical memory immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to"+
nil, " the standby (cached), free and zero page lists (AvailableBytes)",
nil,
),
AvailableKBytes: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "available_k_bytes"),
"(AvailableKBytes)",
nil,
nil,
),
AvailableMBytes: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "available_m_bytes"),
"(AvailableMBytes)",
nil, nil,
nil, nil,
), ),
@@ -86,8 +72,8 @@ func NewOS_MemoryCollector() (Collector, error) {
nil, nil,
nil, nil,
), ),
CacheFaultsPersec: prometheus.NewDesc( CacheFaultsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "cache_faults_persec"), prometheus.BuildFQName(Namespace, subsystem, "cache_faults_total"),
"(CacheFaultsPersec)", "(CacheFaultsPersec)",
nil, nil,
nil, nil,
@@ -104,9 +90,10 @@ func NewOS_MemoryCollector() (Collector, error) {
nil, nil,
nil, nil,
), ),
DemandZeroFaultsPersec: prometheus.NewDesc( DemandZeroFaultsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "demand_zero_faults_persec"), prometheus.BuildFQName(Namespace, subsystem, "demand_zero_faults_total"),
"(DemandZeroFaultsPersec)", "The number of zeroed pages required to satisfy faults. Zeroed pages, pages emptied of previously stored data and filled with zeros, are a security"+
" feature of Windows that prevent processes from seeing data stored by earlier processes that used the memory space (DemandZeroFaults)",
nil, nil,
nil, nil,
), ),
@@ -128,62 +115,57 @@ func NewOS_MemoryCollector() (Collector, error) {
nil, nil,
nil, nil,
), ),
PageFaultsPersec: prometheus.NewDesc( PageFaultsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "page_faults_persec"), prometheus.BuildFQName(Namespace, subsystem, "page_faults_total"),
"(PageFaultsPersec)", "(PageFaultsPersec)",
nil, nil,
nil, nil,
), ),
PageReadsPersec: prometheus.NewDesc( SwapPageReadsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "page_reads_persec"), prometheus.BuildFQName(Namespace, subsystem, "swap_page_reads_total"),
"(PageReadsPersec)", "Number of disk page reads (a single read operation reading several pages is still only counted once) (PageReadsPersec)",
nil, nil,
nil, nil,
), ),
PagesInputPersec: prometheus.NewDesc( SwapPagesReadTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pages_input_persec"), prometheus.BuildFQName(Namespace, subsystem, "swap_pages_read_total"),
"(PagesInputPersec)", "Number of pages read across all page reads (ie counting all pages read even if they are read in a single operation) (PagesInputPersec)",
nil, nil,
nil, nil,
), ),
PagesOutputPersec: prometheus.NewDesc( SwapPagesWrittenTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pages_output_persec"), prometheus.BuildFQName(Namespace, subsystem, "swap_pages_written_total"),
"(PagesOutputPersec)", "Number of pages written across all page writes (ie counting all pages written even if they are written in a single operation) (PagesOutputPersec)",
nil, nil,
nil, nil,
), ),
PagesPersec: prometheus.NewDesc( SwapPageOperationsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pages_persec"), prometheus.BuildFQName(Namespace, subsystem, "swap_page_operations_total"),
"(PagesPersec)", "Total number of swap page read and writes (PagesPersec)",
nil, nil,
nil, nil,
), ),
PageWritesPersec: prometheus.NewDesc( SwapPageWritesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "page_writes_persec"), prometheus.BuildFQName(Namespace, subsystem, "swap_page_writes_total"),
"(PageWritesPersec)", "Number of disk page writes (a single write operation writing several pages is still only counted once) (PageWritesPersec)",
nil, nil,
nil, nil,
), ),
PercentCommittedBytesInUse: prometheus.NewDesc( PoolNonpagedAllocsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "percent_committed_bytes_in_use"), prometheus.BuildFQName(Namespace, subsystem, "pool_nonpaged_allocs_total"),
"(PercentCommittedBytesInUse)", "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"+
nil, " to disk, and must remain in physical memory as long as they are allocated (PoolNonpagedAllocs)",
nil,
),
PoolNonpagedAllocs: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pool_nonpaged_allocs"),
"(PoolNonpagedAllocs)",
nil, nil,
nil, nil,
), ),
PoolNonpagedBytes: prometheus.NewDesc( PoolNonpagedBytes: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pool_nonpaged_bytes"), prometheus.BuildFQName(Namespace, subsystem, "pool_nonpaged_bytes_total"),
"(PoolNonpagedBytes)", "(PoolNonpagedBytes)",
nil, nil,
nil, nil,
), ),
PoolPagedAllocs: prometheus.NewDesc( PoolPagedAllocsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "pool_paged_allocs"), prometheus.BuildFQName(Namespace, subsystem, "pool_paged_allocs_total"),
"(PoolPagedAllocs)", "(PoolPagedAllocs)",
nil, nil,
nil, nil,
@@ -248,21 +230,21 @@ func NewOS_MemoryCollector() (Collector, error) {
nil, nil,
nil, nil,
), ),
TransitionFaultsPersec: prometheus.NewDesc( TransitionFaultsTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transition_faults_persec"), prometheus.BuildFQName(Namespace, subsystem, "transition_faults_total"),
"(TransitionFaultsPersec)", "(TransitionFaultsPersec)",
nil, nil,
nil, nil,
), ),
TransitionPagesRePurposedPersec: prometheus.NewDesc( TransitionPagesRepurposedTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "transition_pages_re_purposed_persec"), prometheus.BuildFQName(Namespace, subsystem, "transition_pages_repurposed_total"),
"(TransitionPagesRePurposedPersec)", "(TransitionPagesRePurposedPersec)",
nil, nil,
nil, nil,
), ),
WriteCopiesPersec: prometheus.NewDesc( WriteCopiesTotal: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "write_copies_persec"), prometheus.BuildFQName(Namespace, subsystem, "write_copies_total"),
"(WriteCopiesPersec)", "The number of page faults caused by attempting to write that were satisfied by copying the page from elsewhere in physical memory (WriteCopiesPersec)",
nil, nil,
nil, nil,
), ),
@@ -271,20 +253,15 @@ func NewOS_MemoryCollector() (Collector, error) {
// Collect sends the metric values for each metric // Collect sends the metric values for each metric
// to the provided prometheus Metric channel. // to the provided prometheus Metric channel.
func (c *OS_MemoryCollector) Collect(ch chan<- prometheus.Metric) error { func (c *MemoryCollector) Collect(ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil { if desc, err := c.collect(ch); err != nil {
log.Error("failed collecting os_memory metrics:", desc, err) log.Error("failed collecting memory metrics:", desc, err)
return err return err
} }
return nil return nil
} }
type Win32_PerfRawData_PerfOS_Memory struct { type Win32_PerfRawData_PerfOS_Memory struct {
// This variable was apparently part of the class, but never filled,
// resulting in a runtime error
// Name string
AvailableBytes uint64 AvailableBytes uint64
AvailableKBytes uint64 AvailableKBytes uint64
AvailableMBytes uint64 AvailableMBytes uint64
@@ -303,7 +280,6 @@ type Win32_PerfRawData_PerfOS_Memory struct {
PagesOutputPersec uint32 PagesOutputPersec uint32
PagesPersec uint32 PagesPersec uint32
PageWritesPersec uint32 PageWritesPersec uint32
PercentCommittedBytesInUse uint32
PoolNonpagedAllocs uint32 PoolNonpagedAllocs uint32
PoolNonpagedBytes uint64 PoolNonpagedBytes uint64
PoolPagedAllocs uint32 PoolPagedAllocs uint32
@@ -322,7 +298,7 @@ type Win32_PerfRawData_PerfOS_Memory struct {
WriteCopiesPersec uint32 WriteCopiesPersec uint32
} }
func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { func (c *MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_PerfOS_Memory var dst []Win32_PerfRawData_PerfOS_Memory
q := queryAll(&dst) q := queryAll(&dst)
if err := wmi.Query(q, &dst); err != nil { if err := wmi.Query(q, &dst); err != nil {
@@ -335,18 +311,6 @@ func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.D
float64(dst[0].AvailableBytes), float64(dst[0].AvailableBytes),
) )
ch <- prometheus.MustNewConstMetric(
c.AvailableKBytes,
prometheus.GaugeValue,
float64(dst[0].AvailableKBytes),
)
ch <- prometheus.MustNewConstMetric(
c.AvailableMBytes,
prometheus.GaugeValue,
float64(dst[0].AvailableMBytes),
)
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.CacheBytes, c.CacheBytes,
prometheus.GaugeValue, prometheus.GaugeValue,
@@ -360,7 +324,7 @@ func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.D
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.CacheFaultsPersec, c.CacheFaultsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].CacheFaultsPersec), float64(dst[0].CacheFaultsPersec),
) )
@@ -378,7 +342,7 @@ func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.D
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.DemandZeroFaultsPersec, c.DemandZeroFaultsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].DemandZeroFaultsPersec), float64(dst[0].DemandZeroFaultsPersec),
) )
@@ -402,49 +366,43 @@ func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.D
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PageFaultsPersec, c.PageFaultsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PageFaultsPersec), float64(dst[0].PageFaultsPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PageReadsPersec, c.SwapPageReadsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PageReadsPersec), float64(dst[0].PageReadsPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PagesInputPersec, c.SwapPagesReadTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PagesInputPersec), float64(dst[0].PagesInputPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PagesOutputPersec, c.SwapPagesWrittenTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PagesOutputPersec), float64(dst[0].PagesOutputPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PagesPersec, c.SwapPageOperationsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PagesPersec), float64(dst[0].PagesPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PageWritesPersec, c.SwapPageWritesTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PageWritesPersec), float64(dst[0].PageWritesPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PercentCommittedBytesInUse, c.PoolNonpagedAllocsTotal,
prometheus.GaugeValue,
float64(dst[0].PercentCommittedBytesInUse),
)
ch <- prometheus.MustNewConstMetric(
c.PoolNonpagedAllocs,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PoolNonpagedAllocs), float64(dst[0].PoolNonpagedAllocs),
) )
@@ -456,7 +414,7 @@ func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.D
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.PoolPagedAllocs, c.PoolPagedAllocsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].PoolPagedAllocs), float64(dst[0].PoolPagedAllocs),
) )
@@ -522,19 +480,19 @@ func (c *OS_MemoryCollector) collect(ch chan<- prometheus.Metric) (*prometheus.D
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.TransitionFaultsPersec, c.TransitionFaultsTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].TransitionFaultsPersec), float64(dst[0].TransitionFaultsPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.TransitionPagesRePurposedPersec, c.TransitionPagesRepurposedTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].TransitionPagesRePurposedPersec), float64(dst[0].TransitionPagesRePurposedPersec),
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.WriteCopiesPersec, c.WriteCopiesTotal,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(dst[0].WriteCopiesPersec), float64(dst[0].WriteCopiesPersec),
) )