Skip to content

Commit

Permalink
Merge pull request #3875 from nats-io/statz-num-subscriptions
Browse files Browse the repository at this point in the history
[ADDED] Number subscriptions in account STATZ
  • Loading branch information
derekcollison committed Feb 17, 2023
2 parents 5eb7d9b + 6ed8237 commit 8a72abf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/events.go
Expand Up @@ -154,6 +154,7 @@ type AccountStat struct {
Conns int `json:"conns"`
LeafNodes int `json:"leafnodes"`
TotalConns int `json:"total_conns"`
NumSubs uint32 `json:"num_subscriptions"`
Sent DataStats `json:"sent"`
Received DataStats `json:"received"`
SlowConsumers int64 `json:"slow_consumers"`
Expand Down Expand Up @@ -1907,6 +1908,7 @@ func (a *Account) statz() *AccountStat {
Conns: localConns,
LeafNodes: leafConns,
TotalConns: localConns + leafConns,
NumSubs: a.sl.Count(),
Received: DataStats{
Msgs: atomic.LoadInt64(&a.inMsgs),
Bytes: atomic.LoadInt64(&a.inBytes)},
Expand Down
4 changes: 2 additions & 2 deletions server/events_test.go
Expand Up @@ -1288,14 +1288,14 @@ func TestAccountReqMonitoring(t *testing.T) {
resp, err = ncSys.Request(statz(acc.Name), nil, time.Second)
require_NoError(t, err)
respContentAcc := []string{`"conns":1,`, `"total_conns":1`, `"slow_consumers":0`, `"sent":{"msgs":0,"bytes":0}`,
`"received":{"msgs":0,"bytes":0}`, fmt.Sprintf(`"acc":"%s"`, acc.Name)}
`"received":{"msgs":0,"bytes":0}`, `"num_subscriptions":`, fmt.Sprintf(`"acc":"%s"`, acc.Name)}
require_Contains(t, string(resp.Data), respContentAcc...)

rIb := ncSys.NewRespInbox()
rSub, err := ncSys.SubscribeSync(rIb)
require_NoError(t, err)
require_NoError(t, ncSys.PublishRequest(pStatz, rIb, nil))
minRespContentForBothAcc := []string{`"conns":1,`, `"total_conns":1`, `"slow_consumers":0`, `"acc":"`}
minRespContentForBothAcc := []string{`"conns":1,`, `"total_conns":1`, `"slow_consumers":0`, `"acc":"`, `"num_subscriptions":`}
resp, err = rSub.NextMsg(time.Second)
require_NoError(t, err)
require_Contains(t, string(resp.Data), minRespContentForBothAcc...)
Expand Down

0 comments on commit 8a72abf

Please sign in to comment.