Skip to content

Commit

Permalink
Merge pull request #41 from martinlindhe/fix_system_uptime
Browse files Browse the repository at this point in the history
system: fix uptime calculation
  • Loading branch information
martinlindhe authored Nov 16, 2016
2 parents 5925816 + a3f44f6 commit 2808da6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions collector/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewSystemCollector() (Collector, error) {
),
SystemUpTime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "system_up_time"),
"PerfOS_System.SystemUpTime",
"SystemUpTime/Frequency_Object",
nil,
nil,
),
Expand All @@ -81,17 +81,20 @@ func (c *SystemCollector) Collect(ch chan<- prometheus.Metric) error {
type Win32_PerfRawData_PerfOS_System struct {
ContextSwitchesPersec uint32
ExceptionDispatchesPersec uint32
Frequency_Object uint64
ProcessorQueueLength uint32
SystemCallsPersec uint32
SystemUpTime uint64
Threads uint32
Timestamp_Object uint64
}

func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
var dst []Win32_PerfRawData_PerfOS_System
if err := wmi.Query(wmi.CreateQuery(&dst, ""), &dst); err != nil {
return nil, err
}

ch <- prometheus.MustNewConstMetric(
c.ContextSwitchesTotal,
prometheus.GaugeValue,
Expand All @@ -115,7 +118,8 @@ func (c *SystemCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc
ch <- prometheus.MustNewConstMetric(
c.SystemUpTime,
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(
c.Threads,
Expand Down

0 comments on commit 2808da6

Please sign in to comment.