mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-01 16:16:35 +00:00
Merge pull request #67 from atezs82/master
Added local_time metric with time_zone label to OS collector
This commit is contained in:
@@ -5,6 +5,7 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
"github.com/StackExchange/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@@ -26,6 +27,8 @@ type OSCollector struct {
|
|||||||
PagingLimitBytes *prometheus.Desc
|
PagingLimitBytes *prometheus.Desc
|
||||||
VirtualMemoryBytes *prometheus.Desc
|
VirtualMemoryBytes *prometheus.Desc
|
||||||
VisibleMemoryBytes *prometheus.Desc
|
VisibleMemoryBytes *prometheus.Desc
|
||||||
|
Time *prometheus.Desc
|
||||||
|
Timezone *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOSCollector ...
|
// NewOSCollector ...
|
||||||
@@ -51,6 +54,18 @@ func NewOSCollector() (Collector, error) {
|
|||||||
nil,
|
nil,
|
||||||
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(
|
Processes: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "processes"),
|
prometheus.BuildFQName(Namespace, subsystem, "processes"),
|
||||||
"OperatingSystem.NumberOfProcesses",
|
"OperatingSystem.NumberOfProcesses",
|
||||||
@@ -117,6 +132,7 @@ type Win32_OperatingSystem struct {
|
|||||||
SizeStoredInPagingFiles uint64
|
SizeStoredInPagingFiles uint64
|
||||||
TotalVirtualMemorySize uint64
|
TotalVirtualMemorySize uint64
|
||||||
TotalVisibleMemorySize uint64
|
TotalVisibleMemorySize uint64
|
||||||
|
LocalDateTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
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
|
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(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PagingFreeBytes,
|
c.PagingFreeBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
|
|||||||
Reference in New Issue
Block a user