Launch self-monitoring in a go-routine
parent
43161bb5da
commit
032cfaa980
38
server.go
38
server.go
|
@ -331,27 +331,31 @@ func (s *Server) StartSelfMonitoring(database, retention string, interval time.D
|
||||||
// Grab the initial stats.
|
// Grab the initial stats.
|
||||||
prev := s.stats.Snapshot()
|
prev := s.stats.Snapshot()
|
||||||
|
|
||||||
for {
|
go func() {
|
||||||
time.Sleep(interval)
|
for {
|
||||||
|
time.Sleep(interval)
|
||||||
|
|
||||||
// Grab the current stats and diff them.
|
// Grab the current stats and diff them.
|
||||||
stats := s.stats.Snapshot()
|
stats := s.stats.Snapshot()
|
||||||
diff := stats.Diff(prev)
|
diff := stats.Diff(prev)
|
||||||
|
|
||||||
// Create the data point and write it.
|
// Create the data point and write it.
|
||||||
point := Point{
|
point := Point{
|
||||||
Name: diff.Name(),
|
Name: diff.Name(),
|
||||||
Tags: map[string]string{"id": strconv.FormatUint(s.id, 10)},
|
Tags: map[string]string{"id": strconv.FormatUint(s.id, 10)},
|
||||||
Fields: make(map[string]interface{}),
|
Fields: make(map[string]interface{}),
|
||||||
|
}
|
||||||
|
diff.Walk(func(k string, v int64) {
|
||||||
|
point.Fields[k] = v
|
||||||
|
})
|
||||||
|
s.WriteSeries(database, retention, []Point{point})
|
||||||
|
|
||||||
|
// Save stats for the next loop.
|
||||||
|
prev = stats
|
||||||
}
|
}
|
||||||
diff.Walk(func(k string, v int64) {
|
}()
|
||||||
point.Fields[k] = v
|
|
||||||
})
|
|
||||||
s.WriteSeries(database, retention, []Point{point})
|
|
||||||
|
|
||||||
// Save stats for the next loop.
|
return nil
|
||||||
prev = stats
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartRetentionPolicyEnforcement launches retention policy enforcement.
|
// StartRetentionPolicyEnforcement launches retention policy enforcement.
|
||||||
|
|
Loading…
Reference in New Issue