From bf39ec5bf173ead25cd20cf57454aaffbe15402f Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Fri, 23 May 2014 13:07:34 +0100 Subject: [PATCH] Do an initial run of the collectors, so that you don't have to wait 60s to see the first values. --- node_exporter.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/node_exporter.go b/node_exporter.go index ee2d5017..f6671aa3 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -50,6 +50,9 @@ func main() { go serveStatus(registry) + log.Printf("Starting initial collection") + collect(collectors) + tick := time.Tick(*interval) for { select { @@ -63,15 +66,7 @@ func main() { case <-tick: log.Printf("Starting new interval") - wg := sync.WaitGroup{} - wg.Add(len(collectors)) - for _, c := range collectors { - go func(c collector.Collector) { - Execute(c) - wg.Done() - }(c) - } - wg.Wait() + collect(collectors) case <-sigUsr1: log.Printf("got signal") @@ -120,6 +115,18 @@ func serveStatus(registry prometheus.Registry) { http.ListenAndServe(*listeningAddress, exp.DefaultCoarseMux) } +func collect(collectors []collector.Collector) { + wg := sync.WaitGroup{} + wg.Add(len(collectors)) + for _, c := range collectors { + go func(c collector.Collector) { + Execute(c) + wg.Done() + }(c) + } + wg.Wait() +} + func Execute(c collector.Collector) { begin := time.Now() updates, err := c.Update()