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 {
|
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 {
|
||||||
|
|
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")
|
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
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue