Browse Source

consul: Adding Stats() method to get various debugging information

pull/19/head
Armon Dadgar 11 years ago
parent
commit
2362b397fa
  1. 19
      consul/client.go
  2. 25
      consul/server.go

19
consul/client.go

@ -9,6 +9,7 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -307,3 +308,21 @@ TRY_RPC:
c.lastRPCTime = time.Now() c.lastRPCTime = time.Now()
return nil return nil
} }
// Stats is used to return statistics for debugging and insight
// for various sub-systems
func (c *Client) Stats() map[string]map[string]string {
toString := func(v uint64) string {
return strconv.FormatUint(v, 10)
}
stats := map[string]map[string]string{
"consul": map[string]string{
"server": "false",
},
"serf-lan": map[string]string{
"members": toString(uint64(len(c.serf.Members()))),
"servers": toString(uint64(len(c.consuls))),
},
}
return stats
}

25
consul/server.go

@ -9,6 +9,7 @@ import (
"net/rpc" "net/rpc"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"sync" "sync"
"time" "time"
) )
@ -452,3 +453,27 @@ func (s *Server) RPC(method string, args interface{}, reply interface{}) error {
addr := s.rpcListener.Addr() addr := s.rpcListener.Addr()
return s.connPool.RPC(addr, method, args, reply) return s.connPool.RPC(addr, method, args, reply)
} }
// Stats is used to return statistics for debugging and insight
// for various sub-systems
func (s *Server) Stats() map[string]map[string]string {
toString := func(v uint64) string {
return strconv.FormatUint(v, 10)
}
stats := map[string]map[string]string{
"consul": map[string]string{
"server": "true",
"leader": fmt.Sprintf("%v", s.IsLeader()),
"bootstrap": fmt.Sprintf("%v", s.config.Bootstrap),
},
"raft": s.raft.Stats(),
"serf-lan": map[string]string{
"members": toString(uint64(len(s.serfLAN.Members()))),
},
"serf-wan": map[string]string{
"members": toString(uint64(len(s.serfWAN.Members()))),
"datacenters": toString(uint64(len(s.remoteConsuls))),
},
}
return stats
}

Loading…
Cancel
Save