Launch self-monitoring in a go-routine

pull/1936/head
Philip O'Toole 2015-03-13 16:57:09 -07:00 committed by Philip O'Toole
parent 43161bb5da
commit 032cfaa980
1 changed files with 21 additions and 17 deletions

View File

@ -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.