agent: Adding Stats() export

This commit is contained in:
Armon Dadgar 2014-02-23 16:42:39 -08:00
parent 11369ca9ad
commit a801eaadf4
1 changed files with 21 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"log" "log"
"net" "net"
"os" "os"
"strconv"
"sync" "sync"
) )
@ -460,3 +461,23 @@ func (a *Agent) UpdateCheck(checkID, status, output string) error {
check.SetStatus(status, output) check.SetStatus(status, output)
return nil return nil
} }
// Stats is used to get various debugging state from the sub-systems
func (a *Agent) Stats() map[string]map[string]string {
toString := func(v uint64) string {
return strconv.FormatUint(v, 10)
}
var stats map[string]map[string]string
if a.server != nil {
stats = a.server.Stats()
} else {
stats = a.client.Stats()
}
stats["agent"] = map[string]string{
"check_monitors": toString(uint64(len(a.checkMonitors))),
"check_ttls": toString(uint64(len(a.checkTTLs))),
"checks": toString(uint64(len(a.state.checks))),
"services": toString(uint64(len(a.state.services))),
}
return stats
}