From 2c45bd6fe929abeaebdab9d4da251405bd4ef5aa Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 29 Apr 2014 10:55:42 -0700 Subject: [PATCH] consul: Expose runtime stats for debugging --- consul/client.go | 1 + consul/server.go | 1 + consul/util.go | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/consul/client.go b/consul/client.go index 5e575ed92d..abd1f500e3 100644 --- a/consul/client.go +++ b/consul/client.go @@ -342,6 +342,7 @@ func (c *Client) Stats() map[string]map[string]string { "known_servers": toString(uint64(len(c.consuls))), }, "serf_lan": c.serf.Stats(), + "runtime": runtimeStats(), } return stats } diff --git a/consul/server.go b/consul/server.go index c7a613bf6f..a830e31f73 100644 --- a/consul/server.go +++ b/consul/server.go @@ -528,6 +528,7 @@ func (s *Server) Stats() map[string]map[string]string { "raft": s.raft.Stats(), "serf_lan": s.serfLAN.Stats(), "serf_wan": s.serfWAN.Stats(), + "runtime": runtimeStats(), } return stats } diff --git a/consul/util.go b/consul/util.go index ffca9961cb..f2c29d40d5 100644 --- a/consul/util.go +++ b/consul/util.go @@ -7,6 +7,7 @@ import ( "net" "os" "path/filepath" + "runtime" "strconv" ) @@ -139,3 +140,15 @@ func uint64ToBytes(u uint64) []byte { binary.BigEndian.PutUint64(buf, u) return buf } + +// runtimeStats is used to return various runtime information +func runtimeStats() map[string]string { + return map[string]string{ + "os": runtime.GOOS, + "arch": runtime.GOARCH, + "version": runtime.Version(), + "max_procs": strconv.FormatInt(int64(runtime.GOMAXPROCS(0)), 10), + "goroutines": strconv.FormatInt(int64(runtime.NumGoroutine()), 10), + "cpu_count": strconv.FormatInt(int64(runtime.NumCPU()), 10), + } +}