mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 06:59:44 -08:00
Do an initial run of the collectors, so that you don't
have to wait 60s to see the first values.
This commit is contained in:
parent
b959697368
commit
bf39ec5bf1
|
@ -50,6 +50,9 @@ func main() {
|
||||||
|
|
||||||
go serveStatus(registry)
|
go serveStatus(registry)
|
||||||
|
|
||||||
|
log.Printf("Starting initial collection")
|
||||||
|
collect(collectors)
|
||||||
|
|
||||||
tick := time.Tick(*interval)
|
tick := time.Tick(*interval)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -63,15 +66,7 @@ func main() {
|
||||||
|
|
||||||
case <-tick:
|
case <-tick:
|
||||||
log.Printf("Starting new interval")
|
log.Printf("Starting new interval")
|
||||||
wg := sync.WaitGroup{}
|
collect(collectors)
|
||||||
wg.Add(len(collectors))
|
|
||||||
for _, c := range collectors {
|
|
||||||
go func(c collector.Collector) {
|
|
||||||
Execute(c)
|
|
||||||
wg.Done()
|
|
||||||
}(c)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
case <-sigUsr1:
|
case <-sigUsr1:
|
||||||
log.Printf("got signal")
|
log.Printf("got signal")
|
||||||
|
@ -120,6 +115,18 @@ func serveStatus(registry prometheus.Registry) {
|
||||||
http.ListenAndServe(*listeningAddress, exp.DefaultCoarseMux)
|
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) {
|
func Execute(c collector.Collector) {
|
||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
updates, err := c.Update()
|
updates, err := c.Update()
|
||||||
|
|
Loading…
Reference in a new issue