info update and add store stat

This commit is contained in:
siddontang 2014-10-15 10:41:43 +08:00
parent f05398cdf9
commit 028b9fbd55
3 changed files with 25 additions and 25 deletions

View File

@ -2566,15 +2566,7 @@ Very dangerous to use!!!
Return information and statistic about the server in a format that is simple to parse by computers and easy to read by humans. Return information and statistic about the server in a format that is simple to parse by computers and easy to read by humans.
The optional parameter can be used to select a specific section of information: The optional parameter can be used to select a specific section of information. When no parameter is provided, all will return.
+ server: General information about the Redis server
+ client: Client connections section
+ mem: Memory consumption related information
+ goroutine: Goroutine num
+ persistence: Strorage related information
When no parameter is provided, all will return.
### TIME ### TIME

View File

@ -198,3 +198,7 @@ func (l *Ledis) onDataExpired() {
} }
} }
func (l *Ledis) StoreStat() *store.Stat {
return l.ldb.Stat()
}

View File

@ -55,6 +55,7 @@ func newInfo(app *App) (i *info, err error) {
func (i *info) addClients(delta int64) { func (i *info) addClients(delta int64) {
atomic.AddInt64(&i.Clients.ConnectedClients, delta) atomic.AddInt64(&i.Clients.ConnectedClients, delta)
} }
func (i *info) Close() { func (i *info) Close() {
} }
@ -82,10 +83,8 @@ func (i *info) Dump(section string) []byte {
i.dumpClients(buf) i.dumpClients(buf)
case "mem": case "mem":
i.dumpMem(buf) i.dumpMem(buf)
case "persistence": case "store":
i.dumpPersistence(buf) i.dumpStore(buf)
case "goroutine":
i.dumpGoroutine(buf)
case "replication": case "replication":
i.dumpReplication(buf) i.dumpReplication(buf)
default: default:
@ -103,14 +102,12 @@ type infoPair struct {
func (i *info) dumpAll(buf *bytes.Buffer) { func (i *info) dumpAll(buf *bytes.Buffer) {
i.dumpServer(buf) i.dumpServer(buf)
buf.Write(Delims) buf.Write(Delims)
i.dumpPersistence(buf) i.dumpStore(buf)
buf.Write(Delims) buf.Write(Delims)
i.dumpClients(buf) i.dumpClients(buf)
buf.Write(Delims) buf.Write(Delims)
i.dumpMem(buf) i.dumpMem(buf)
buf.Write(Delims) buf.Write(Delims)
i.dumpGoroutine(buf)
buf.Write(Delims)
i.dumpReplication(buf) i.dumpReplication(buf)
} }
@ -121,7 +118,9 @@ func (i *info) dumpServer(buf *bytes.Buffer) {
infoPair{"process_id", i.Server.ProceessId}, infoPair{"process_id", i.Server.ProceessId},
infoPair{"addr", i.app.cfg.Addr}, infoPair{"addr", i.app.cfg.Addr},
infoPair{"http_addr", i.app.cfg.HttpAddr}, infoPair{"http_addr", i.app.cfg.HttpAddr},
infoPair{"readonly", i.app.cfg.Readonly}) infoPair{"readonly", i.app.cfg.Readonly},
infoPair{"goroutine_num", runtime.NumGoroutine()},
)
} }
func (i *info) dumpClients(buf *bytes.Buffer) { func (i *info) dumpClients(buf *bytes.Buffer) {
@ -140,16 +139,21 @@ func (i *info) dumpMem(buf *bytes.Buffer) {
infoPair{"mem_alloc_human", getMemoryHuman(mem.Alloc)}) infoPair{"mem_alloc_human", getMemoryHuman(mem.Alloc)})
} }
func (i *info) dumpGoroutine(buf *bytes.Buffer) { func (i *info) dumpStore(buf *bytes.Buffer) {
buf.WriteString("# Goroutine\r\n") buf.WriteString("# Store\r\n")
i.dumpPairs(buf, infoPair{"goroutine_num", runtime.NumGoroutine()}) s := i.app.ldb.StoreStat()
}
func (i *info) dumpPersistence(buf *bytes.Buffer) { i.dumpPairs(buf, infoPair{"name", i.Persistence.DBName},
buf.WriteString("# Persistence\r\n") infoPair{"get", s.GetNum},
infoPair{"get_missing", s.GetMissingNum},
i.dumpPairs(buf, infoPair{"db_name", i.Persistence.DBName}) infoPair{"put", s.PutNum},
infoPair{"delete", s.DeleteNum},
infoPair{"iter", s.IterNum},
infoPair{"iter_seek", s.IterSeekNum},
infoPair{"iter_close", s.IterCloseNum},
infoPair{"batch_commit", s.BatchCommitNum},
)
} }
func (i *info) dumpReplication(buf *bytes.Buffer) { func (i *info) dumpReplication(buf *bytes.Buffer) {