sort stats for testing. check for nil stats before updating
parent
e7eb3838f5
commit
e205abbcb4
5
shard.go
5
shard.go
|
@ -89,6 +89,7 @@ func (s *Shard) open(path string, conn MessagingConn) error {
|
||||||
if s.stats == nil {
|
if s.stats == nil {
|
||||||
s.stats = NewStats("shard")
|
s.stats = NewStats("shard")
|
||||||
}
|
}
|
||||||
|
s.stats.Inc("open")
|
||||||
|
|
||||||
// Return an error if the shard is already open.
|
// Return an error if the shard is already open.
|
||||||
if s.store != nil {
|
if s.store != nil {
|
||||||
|
@ -179,7 +180,9 @@ func (s *Shard) close() error {
|
||||||
if s.store != nil {
|
if s.store != nil {
|
||||||
_ = s.store.Close()
|
_ = s.store.Close()
|
||||||
}
|
}
|
||||||
s.stats.Inc("close")
|
if s.stats != nil {
|
||||||
|
s.stats.Inc("close")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
stats.go
13
stats.go
|
@ -2,6 +2,7 @@ package influxdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -117,12 +118,18 @@ func (s *Stats) Snapshot() *Stats {
|
||||||
func (s *Stats) String() string {
|
func (s *Stats) String() string {
|
||||||
var out string
|
var out string
|
||||||
stat := s.Snapshot()
|
stat := s.Snapshot()
|
||||||
|
var keys []string
|
||||||
|
for k, _ := range stat.m {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
out += `{"` + stat.name + `":[`
|
out += `{"` + stat.name + `":[`
|
||||||
var j int
|
var j int
|
||||||
for k, v := range stat.m {
|
for _, k := range keys {
|
||||||
out += `{"` + k + `":` + fmt.Sprintf("%d", v.i) + `}`
|
v := stat.m[k].i
|
||||||
|
out += `{"` + k + `":` + fmt.Sprintf("%d", v) + `}`
|
||||||
j++
|
j++
|
||||||
if j != len(stat.m) {
|
if j != len(keys) {
|
||||||
out += `,`
|
out += `,`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue