From 015670d04ee20d409b77f3561ef0d4d3cddc2abb Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sun, 23 Feb 2014 16:42:39 -0800 Subject: [PATCH] agent: Adding Stats() export --- command/agent/agent.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/command/agent/agent.go b/command/agent/agent.go index dcbd462598..caaf1a9a37 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -9,6 +9,7 @@ import ( "log" "net" "os" + "strconv" "sync" ) @@ -460,3 +461,23 @@ func (a *Agent) UpdateCheck(checkID, status, output string) error { check.SetStatus(status, output) 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 +}