mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-21 12:16:36 +00:00
system: fix uptime calculation, fixes #40
This commit is contained in:
@@ -55,7 +55,7 @@ func NewSystemCollector() (Collector, error) {
|
|||||||
),
|
),
|
||||||
SystemUpTime: prometheus.NewDesc(
|
SystemUpTime: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "system_up_time"),
|
prometheus.BuildFQName(Namespace, subsystem, "system_up_time"),
|
||||||
"PerfOS_System.SystemUpTime",
|
"SystemUpTime/Frequency_Object",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
@@ -81,10 +81,12 @@ func (c *SystemCollector) Collect(ch chan<- prometheus.Metric) error {
|
|||||||
type Win32_PerfRawData_PerfOS_System struct {
|
type Win32_PerfRawData_PerfOS_System struct {
|
||||||
ContextSwitchesPersec uint32
|
ContextSwitchesPersec uint32
|
||||||
ExceptionDispatchesPersec uint32
|
ExceptionDispatchesPersec uint32
|
||||||
|
Frequency_Object uint64
|
||||||
ProcessorQueueLength uint32
|
ProcessorQueueLength uint32
|
||||||
SystemCallsPersec uint32
|
SystemCallsPersec uint32
|
||||||
SystemUpTime uint64
|
SystemUpTime uint64
|
||||||
Threads uint32
|
Threads uint32
|
||||||
|
Timestamp_Object uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
@@ -92,6 +94,7 @@ func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc
|
|||||||
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.ContextSwitchesTotal,
|
c.ContextSwitchesTotal,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
@@ -115,7 +118,8 @@ func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc
|
|||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.SystemUpTime,
|
c.SystemUpTime,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(dst[0].SystemUpTime),
|
// convert from Windows timestamp (1 jan 1601) to unix timestamp (1 jan 1970)
|
||||||
|
float64(dst[0].SystemUpTime-116444736000000000)/float64(dst[0].Frequency_Object),
|
||||||
)
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.Threads,
|
c.Threads,
|
||||||
|
|||||||
Reference in New Issue
Block a user