sort stats for testing. check for nil stats before updating

pull/2398/head
Cory LaNou 2015-04-22 16:03:37 -06:00
parent e7eb3838f5
commit e205abbcb4
2 changed files with 14 additions and 4 deletions

View File

@ -89,6 +89,7 @@ func (s *Shard) open(path string, conn MessagingConn) error {
if s.stats == nil {
s.stats = NewStats("shard")
}
s.stats.Inc("open")
// Return an error if the shard is already open.
if s.store != nil {
@ -179,7 +180,9 @@ func (s *Shard) close() error {
if s.store != nil {
_ = s.store.Close()
}
s.stats.Inc("close")
if s.stats != nil {
s.stats.Inc("close")
}
return nil
}

View File

@ -2,6 +2,7 @@ package influxdb
import (
"fmt"
"sort"
"sync"
)
@ -117,12 +118,18 @@ func (s *Stats) Snapshot() *Stats {
func (s *Stats) String() string {
var out string
stat := s.Snapshot()
var keys []string
for k, _ := range stat.m {
keys = append(keys, k)
}
sort.Strings(keys)
out += `{"` + stat.name + `":[`
var j int
for k, v := range stat.m {
out += `{"` + k + `":` + fmt.Sprintf("%d", v.i) + `}`
for _, k := range keys {
v := stat.m[k].i
out += `{"` + k + `":` + fmt.Sprintf("%d", v) + `}`
j++
if j != len(stat.m) {
if j != len(keys) {
out += `,`
}
}