diff --git a/TODO.md b/TODO.md index a507a694..ab77bccf 100644 --- a/TODO.md +++ b/TODO.md @@ -20,7 +20,7 @@ - [ ] Add to varz, time for slow consumers, peek or total connections, memory, etc. - [ ] Add starttime and uptime to connz list. - [ ] Add in HTTP requests to varz? -- [ ] Add favico and help link for monitoring? +- [X] Add favico and help link for monitoring? - [X] Better user/pass support using bcrypt etc. - [X] SSL/TLS support - [X] Add support for / to point to varz, connz, etc.. diff --git a/server/client.go b/server/client.go index e246da3c..59731a64 100644 --- a/server/client.go +++ b/server/client.go @@ -31,22 +31,23 @@ const ( ) type client struct { - mu sync.Mutex - typ int - cid uint64 - lang string - opts clientOpts - nc net.Conn - mpay int - ncs string - bw *bufio.Writer - srv *Server - subs *hashmap.HashMap - pcd map[*client]struct{} - atmr *time.Timer - ptmr *time.Timer - pout int - msgb [msgScratchSize]byte + mu sync.Mutex + typ int + cid uint64 + lang string + opts clientOpts + start time.Time + nc net.Conn + mpay int + ncs string + bw *bufio.Writer + srv *Server + subs *hashmap.HashMap + pcd map[*client]struct{} + atmr *time.Timer + ptmr *time.Timer + pout int + msgb [msgScratchSize]byte parseState stats diff --git a/server/monitor.go b/server/monitor.go index 9c4ba019..581da19f 100644 --- a/server/monitor.go +++ b/server/monitor.go @@ -34,21 +34,23 @@ type Connz struct { // ConnInfo has detailed information on a per connection basis. type ConnInfo struct { - Cid uint64 `json:"cid"` - IP string `json:"ip"` - Port int `json:"port"` - Pending int `json:"pending_bytes"` - InMsgs int64 `json:"in_msgs"` - OutMsgs int64 `json:"out_msgs"` - InBytes int64 `json:"in_bytes"` - OutBytes int64 `json:"out_bytes"` - NumSubs uint32 `json:"subscriptions"` - Name string `json:"name,omitempty"` - Lang string `json:"lang,omitempty"` - Version string `json:"version,omitempty"` - TLSVersion string `json:"tls_version,omitempty"` - TLSCipher string `json:"tls_cipher_suite,omitempty"` - Subs []string `json:"subscriptions_list,omitempty"` + Cid uint64 `json:"cid"` + IP string `json:"ip"` + Port int `json:"port"` + Start time.Time `json:"start"` + Uptime string `json:"uptime"` + Pending int `json:"pending_bytes"` + InMsgs int64 `json:"in_msgs"` + OutMsgs int64 `json:"out_msgs"` + InBytes int64 `json:"in_bytes"` + OutBytes int64 `json:"out_bytes"` + NumSubs uint32 `json:"subscriptions"` + Name string `json:"name,omitempty"` + Lang string `json:"lang,omitempty"` + Version string `json:"version,omitempty"` + TLSVersion string `json:"tls_version,omitempty"` + TLSCipher string `json:"tls_cipher_suite,omitempty"` + Subs []string `json:"subscriptions_list,omitempty"` } const DefaultConnListSize = 1024 @@ -114,12 +116,17 @@ func (s *Server) HandleConnz(w http.ResponseWriter, r *http.Request) { } pairs = pairs[minoff:maxoff] + // Use same now for all uptime calculations. + now := time.Now() + for _, pair := range pairs { client := pair.Val client.mu.Lock() ci := &ConnInfo{ Cid: client.cid, + Start: client.start, + Uptime: myUptime(now.Sub(client.start)), InMsgs: client.inMsgs, OutMsgs: client.outMsgs, InBytes: client.inBytes, diff --git a/server/monitor_test.go b/server/monitor_test.go index 31caeb9e..be3737c0 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -218,6 +218,7 @@ func TestConnz(t *testing.T) { } defer resp.Body.Close() body, err = ioutil.ReadAll(resp.Body) + if err != nil { t.Fatalf("Got an error reading the body: %v\n", err) } @@ -270,6 +271,12 @@ func TestConnz(t *testing.T) { if ci.OutBytes != 5 { t.Fatalf("Expected OutBytes of 1, got %v\n", ci.OutBytes) } + if ci.Start.IsZero() { + t.Fatalf("Expected Start to be valid\n") + } + if ci.Uptime == "" { + t.Fatalf("Expected Uptime to be valid\n") + } // Test JSONP respj, errj := http.Get(fmt.Sprintf("http://localhost:%d/", DEFAULT_HTTP_PORT) + "connz?callback=callback") diff --git a/server/server.go b/server/server.go index db19ddd2..e7c400c8 100644 --- a/server/server.go +++ b/server/server.go @@ -432,7 +432,7 @@ func (s *Server) startMonitoring(secure bool) { } func (s *Server) createClient(conn net.Conn) *client { - c := &client{srv: s, nc: conn, opts: defaultOpts, mpay: s.info.MaxPayload} + c := &client{srv: s, nc: conn, opts: defaultOpts, mpay: s.info.MaxPayload, start: time.Now()} // Grab JSON info string s.mu.Lock()