1
0
Fork 0

Instrument Cluster service

master
Philip O'Toole 3 years ago
parent 0ab519f6dc
commit cbc2a686db

@ -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()

@ -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.

Loading…
Cancel
Save