2016-09-19 07:02:05 +00:00
|
|
|
// returns data points from Win32_ComputerSystem
|
|
|
|
// https://msdn.microsoft.com/en-us/library/aa394102 - Win32_ComputerSystem class
|
|
|
|
|
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/StackExchange/wmi"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2018-04-05 05:27:26 +00:00
|
|
|
"github.com/prometheus/common/log"
|
2016-09-19 07:02:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Factories["cs"] = NewCSCollector
|
|
|
|
}
|
|
|
|
|
|
|
|
// A CSCollector is a Prometheus collector for WMI metrics
|
|
|
|
type CSCollector struct {
|
|
|
|
PhysicalMemoryBytes *prometheus.Desc
|
|
|
|
LogicalProcessors *prometheus.Desc
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewCSCollector ...
|
|
|
|
func NewCSCollector() (Collector, error) {
|
|
|
|
const subsystem = "cs"
|
|
|
|
|
|
|
|
return &CSCollector{
|
|
|
|
LogicalProcessors: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "logical_processors"),
|
|
|
|
"ComputerSystem.NumberOfLogicalProcessors",
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
PhysicalMemoryBytes: prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, subsystem, "physical_memory_bytes"),
|
|
|
|
"ComputerSystem.TotalPhysicalMemory",
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect sends the metric values for each metric
|
|
|
|
// to the provided prometheus Metric channel.
|
|
|
|
func (c *CSCollector) Collect(ch chan<- prometheus.Metric) error {
|
|
|
|
if desc, err := c.collect(ch); err != nil {
|
2018-04-05 05:27:26 +00:00
|
|
|
log.Error("failed collecting cs metrics:", desc, err)
|
2016-09-19 07:02:05 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Win32_ComputerSystem struct {
|
|
|
|
NumberOfLogicalProcessors uint32
|
|
|
|
TotalPhysicalMemory uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
|
|
|
var dst []Win32_ComputerSystem
|
|
|
|
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.LogicalProcessors,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(dst[0].NumberOfLogicalProcessors),
|
|
|
|
)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
c.PhysicalMemoryBytes,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(dst[0].TotalPhysicalMemory),
|
|
|
|
)
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|