Add pending_events stat

This commit is contained in:
tidwall 2022-07-11 08:39:40 -07:00
parent 59778e6092
commit b883f358d5
1 changed files with 16 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import (
"sync"
"time"
"github.com/tidwall/buntdb"
"github.com/tidwall/resp"
"github.com/tidwall/tile38/core"
)
@ -167,17 +168,17 @@ func (s *Server) basicStats(m map[string]interface{}) {
m["in_memory_size"] = sz
points := 0
objects := 0
strings := 0
nstrings := 0
s.cols.Ascend(nil, func(v interface{}) bool {
col := v.(*collectionKeyContainer).col
points += col.PointCount()
objects += col.Count()
strings += col.StringCount()
nstrings += col.StringCount()
return true
})
m["num_points"] = points
m["num_objects"] = objects
m["num_strings"] = strings
m["num_strings"] = nstrings
mem := readMemStats()
avgsz := 0
if points != 0 {
@ -194,6 +195,18 @@ func (s *Server) basicStats(m map[string]interface{}) {
m["cpus"] = runtime.NumCPU()
n, _ := runtime.ThreadCreateProfile(nil)
m["threads"] = float64(n)
var nevents int
s.qdb.View(func(tx *buntdb.Tx) error {
// All entries in the buntdb log are events, except for one, which
// is "hook:idx".
nevents, _ = tx.Len()
nevents -= 1 // Ignore the "hook:idx"
if nevents < 0 {
nevents = 0
}
return nil
})
m["pending_events"] = nevents
}
// extStats populates the passed map with extended system/go/tile38 statistics