Write totals, not diff, of internal stats

pull/1936/head
Philip O'Toole 2015-03-13 17:23:55 -07:00 committed by Philip O'Toole
parent 032cfaa980
commit 50d2470041
2 changed files with 4 additions and 13 deletions

View File

@ -185,6 +185,7 @@ func Run(config *Config, join, version string, logWriter *os.File) (*messaging.B
if config.Statistics.Enabled { if config.Statistics.Enabled {
database := config.Statistics.Database database := config.Statistics.Database
policy := config.Statistics.RetentionPolicy policy := config.Statistics.RetentionPolicy
interval := time.Duration(config.Statistics.WriteInterval)
// Ensure database exists. // Ensure database exists.
if err := s.CreateDatabaseIfNotExists(database); err != nil { if err := s.CreateDatabaseIfNotExists(database); err != nil {

View File

@ -328,30 +328,20 @@ func (s *Server) StartSelfMonitoring(database, retention string, interval time.D
return fmt.Errorf("statistics check interval must be non-zero") return fmt.Errorf("statistics check interval must be non-zero")
} }
// Grab the initial stats.
prev := s.stats.Snapshot()
go func() { go func() {
for { for {
time.Sleep(interval) 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. // Create the data point and write it.
point := Point{ point := Point{
Name: diff.Name(), Name: s.stats.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) { s.stats.Walk(func(k string, v int64) {
point.Fields[k] = v point.Fields[k] = int(v)
}) })
s.WriteSeries(database, retention, []Point{point}) s.WriteSeries(database, retention, []Point{point})
// Save stats for the next loop.
prev = stats
} }
}() }()