From cbc2a686db83363b12c58e5159ee3680796edb5e Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 28 Apr 2021 21:13:43 -0400 Subject: [PATCH] Instrument Cluster service --- cluster/service.go | 28 ++++++++++++++++++++++++++++ tcp/mux.go | 6 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cluster/service.go b/cluster/service.go index 7f7d37a1..c148c64c 100644 --- a/cluster/service.go +++ b/cluster/service.go @@ -2,18 +2,32 @@ package cluster import ( "encoding/binary" + "expvar" "fmt" "io" "io/ioutil" "log" "net" "os" + "strconv" "sync" "time" "github.com/golang/protobuf/proto" ) +// stats captures stats for the Cluster service. +var stats *expvar.Map + +const ( + numGetNodeAPI = "num_get_node_api" +) + +func init() { + stats = expvar.NewMap("cluster") + stats.Add(numGetNodeAPI, 0) +} + // Transport is the interface the network layer must provide. type Transport interface { net.Listener @@ -123,6 +137,18 @@ func (s *Service) GetNodeAPIAddr(nodeAddr string) (string, error) { return a.Url, nil } +// Stats returns status of the Service. +func (s *Service) Stats() (interface{}, error) { + st := map[string]string{ + "addr": s.addr.String(), + "timeout": s.timeout.String(), + "https": strconv.FormatBool(s.https), + "api_addr": s.apiAddr, + } + + return st, nil +} + func (s *Service) serve() error { defer s.wg.Done() for { @@ -159,6 +185,8 @@ func (s *Service) handleConn(conn net.Conn) { switch c.Type { case Command_COMMAND_TYPE_GET_NODE_API_URL: + stats.Add(numGetNodeAPI, 1) + s.mu.RLock() defer s.mu.RUnlock() diff --git a/tcp/mux.go b/tcp/mux.go index 868f0def..ec43ccc1 100644 --- a/tcp/mux.go +++ b/tcp/mux.go @@ -144,7 +144,11 @@ func NewTLSMux(ln net.Listener, adv net.Addr, cert, key, caCert string) (*Mux, e // Serve handles connections from ln and multiplexes then across registered listener. func (mux *Mux) Serve() error { - mux.Logger.Printf("mux serving on %s, advertising %s", mux.ln.Addr().String(), mux.addr) + tlsStr := "" + if mux.tlsConfig != nil { + tlsStr = "TLS " + } + mux.Logger.Printf("%smux serving on %s, advertising %s", tls, mux.ln.Addr().String(), mux.addr) for { // Wait for the next connection.