Skip to content

Commit

Permalink
Reset before collecting. Parse flag. Logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitagarwal003 committed May 20, 2018
1 parent 9a4c568 commit 8753fe5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.Lock()
defer c.Unlock()

c.usedMemory.Reset()
c.totalMemory.Reset()
c.dutyCycle.Reset()
c.powerUsage.Reset()
c.temperature.Reset()
c.fanSpeed.Reset()

numDevices, err := gonvml.DeviceCount()
if err != nil {
log.Printf("DeviceCount() error: %v", err)
Expand Down Expand Up @@ -180,13 +187,14 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
}

func main() {
err := gonvml.Initialize()
if err != nil {
flag.Parse()

if err := gonvml.Initialize(); err != nil {
log.Fatalf("Couldn't initialize gonvml: %v", err)
}
defer gonvml.Shutdown()

prometheus.MustRegister(NewCollector())

http.ListenAndServe(*addr, promhttp.Handler())
log.Fatalf("ListenAndServe error: %v", http.ListenAndServe(*addr, promhttp.Handler()))
}

0 comments on commit 8753fe5

Please sign in to comment.