diff --git a/collector/os.go b/collector/os.go index e4f290da..db99db8d 100644 --- a/collector/os.go +++ b/collector/os.go @@ -5,7 +5,8 @@ package collector import ( "log" - + "time" + "github.com/StackExchange/wmi" "github.com/prometheus/client_golang/prometheus" ) @@ -26,6 +27,8 @@ type OSCollector struct { PagingLimitBytes *prometheus.Desc VirtualMemoryBytes *prometheus.Desc VisibleMemoryBytes *prometheus.Desc + Time *prometheus.Desc + Timezone *prometheus.Desc } // NewOSCollector ... @@ -51,6 +54,18 @@ func NewOSCollector() (Collector, error) { nil, nil, ), + Time: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "time"), + "OperatingSystem.LocalDateTime", + nil, + nil, + ), + Timezone: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "timezone"), + "OperatingSystem.LocalDateTime", + []string{"timezone"}, + nil, + ), Processes: prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "processes"), "OperatingSystem.NumberOfProcesses", @@ -117,6 +132,7 @@ type Win32_OperatingSystem struct { SizeStoredInPagingFiles uint64 TotalVirtualMemorySize uint64 TotalVisibleMemorySize uint64 + LocalDateTime time.Time } func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { @@ -131,6 +147,23 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er float64(dst[0].FreePhysicalMemory*1024), // KiB -> bytes ) + time := dst[0].LocalDateTime + + ch <- prometheus.MustNewConstMetric( + c.Time, + prometheus.GaugeValue, + float64(time.Unix()), + ) + + timezoneName, _ := time.Zone() + + ch <- prometheus.MustNewConstMetric( + c.Timezone, + prometheus.GaugeValue, + 1.0, + timezoneName, + ) + ch <- prometheus.MustNewConstMetric( c.PagingFreeBytes, prometheus.GaugeValue,