Write totals, not diff, of internal stats
parent
032cfaa980
commit
50d2470041
|
@ -185,6 +185,7 @@ func Run(config *Config, join, version string, logWriter *os.File) (*messaging.B
|
|||
if config.Statistics.Enabled {
|
||||
database := config.Statistics.Database
|
||||
policy := config.Statistics.RetentionPolicy
|
||||
interval := time.Duration(config.Statistics.WriteInterval)
|
||||
|
||||
// Ensure database exists.
|
||||
if err := s.CreateDatabaseIfNotExists(database); err != nil {
|
||||
|
|
16
server.go
16
server.go
|
@ -328,30 +328,20 @@ func (s *Server) StartSelfMonitoring(database, retention string, interval time.D
|
|||
return fmt.Errorf("statistics check interval must be non-zero")
|
||||
}
|
||||
|
||||
// Grab the initial stats.
|
||||
prev := s.stats.Snapshot()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(interval)
|
||||
|
||||
// Grab the current stats and diff them.
|
||||
stats := s.stats.Snapshot()
|
||||
diff := stats.Diff(prev)
|
||||
|
||||
// Create the data point and write it.
|
||||
point := Point{
|
||||
Name: diff.Name(),
|
||||
Name: s.stats.Name(),
|
||||
Tags: map[string]string{"id": strconv.FormatUint(s.id, 10)},
|
||||
Fields: make(map[string]interface{}),
|
||||
}
|
||||
diff.Walk(func(k string, v int64) {
|
||||
point.Fields[k] = v
|
||||
s.stats.Walk(func(k string, v int64) {
|
||||
point.Fields[k] = int(v)
|
||||
})
|
||||
s.WriteSeries(database, retention, []Point{point})
|
||||
|
||||
// Save stats for the next loop.
|
||||
prev = stats
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Reference in New Issue