From df02549dc25c57a02bd0f4947dfb32144adeff9a Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Mon, 16 May 2016 12:46:30 -0700 Subject: [PATCH] Report total subscriptions under /varz --- server/monitor.go | 39 ++++++++++++++++++++------------------- server/monitor_test.go | 3 +++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/server/monitor.go b/server/monitor.go index 8f785701..9bb035f1 100644 --- a/server/monitor.go +++ b/server/monitor.go @@ -356,25 +356,25 @@ func (s *Server) HandleSubsz(w http.ResponseWriter, r *http.Request) { type Varz struct { *Info *Options - Port int `json:"port"` - MaxPayload int `json:"max_payload"` - Start time.Time `json:"start"` - Now time.Time `json:"now"` - Uptime string `json:"uptime"` - Mem int64 `json:"mem"` - Cores int `json:"cores"` - CPU float64 `json:"cpu"` - Connections int `json:"connections"` - TotalConnections uint64 `json:"total_connections"` - Routes int `json:"routes"` - Remotes int `json:"remotes"` - InMsgs int64 `json:"in_msgs"` - OutMsgs int64 `json:"out_msgs"` - InBytes int64 `json:"in_bytes"` - OutBytes int64 `json:"out_bytes"` - SlowConsumers int64 `json:"slow_consumers"` - - HTTPReqStats map[string]uint64 `json:"http_req_stats"` + Port int `json:"port"` + MaxPayload int `json:"max_payload"` + Start time.Time `json:"start"` + Now time.Time `json:"now"` + Uptime string `json:"uptime"` + Mem int64 `json:"mem"` + Cores int `json:"cores"` + CPU float64 `json:"cpu"` + Connections int `json:"connections"` + TotalConnections uint64 `json:"total_connections"` + Routes int `json:"routes"` + Remotes int `json:"remotes"` + InMsgs int64 `json:"in_msgs"` + OutMsgs int64 `json:"out_msgs"` + InBytes int64 `json:"in_bytes"` + OutBytes int64 `json:"out_bytes"` + SlowConsumers int64 `json:"slow_consumers"` + Subscriptions uint32 `json:"subscriptions"` + HTTPReqStats map[string]uint64 `json:"http_req_stats"` } type usage struct { @@ -456,6 +456,7 @@ func (s *Server) HandleVarz(w http.ResponseWriter, r *http.Request) { v.OutMsgs = s.outMsgs v.OutBytes = s.outBytes v.SlowConsumers = s.slowConsumers + v.Subscriptions = s.sl.Count() s.httpReqStats[VarzPath]++ v.HTTPReqStats = s.httpReqStats s.mu.Unlock() diff --git a/server/monitor_test.go b/server/monitor_test.go index 93d6c9d2..d7b11998 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -168,6 +168,9 @@ func TestVarz(t *testing.T) { if v.OutBytes != 5 { t.Fatalf("Expected OutBytes of 5, got %v\n", v.OutBytes) } + if v.Subscriptions != 1 { + t.Fatalf("Expected Subscriptions of 1, got %v\n", v.Subscriptions) + } // Test JSONP respj, errj := http.Get(fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + "varz?callback=callback")