Exposing reserved memory in jsz/varz

Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
Matthias Hanel
2021-09-16 18:55:50 -04:00
parent 670a81e213
commit 5b9d20871d
2 changed files with 15 additions and 5 deletions

View File

@@ -49,10 +49,12 @@ type JetStreamConfig struct {
}
type JetStreamStats struct {
Memory uint64 `json:"memory"`
Store uint64 `json:"storage"`
Accounts int `json:"accounts,omitempty"`
API JetStreamAPIStats `json:"api"`
Memory uint64 `json:"memory"`
Store uint64 `json:"storage"`
Accounts int `json:"accounts,omitempty"`
API JetStreamAPIStats `json:"api"`
ReservedMemory uint64 `json:"reserved_memory"`
ReservedStore uint64 `json:"reserved_storage"`
}
type JetStreamAccountLimits struct {
@@ -1645,6 +1647,8 @@ func (js *jetStream) usageStats() *JetStreamStats {
var stats JetStreamStats
js.mu.RLock()
stats.Accounts = len(js.accounts)
stats.ReservedMemory = (uint64)(js.memReserved)
stats.ReservedStore = (uint64)(js.storeReserved)
js.mu.RUnlock()
stats.API.Total = (uint64)(atomic.LoadInt64(&js.apiCalls))
stats.API.Errors = (uint64)(atomic.LoadInt64(&js.apiErrors))

View File

@@ -3959,7 +3959,7 @@ func TestMonitorJsz(t *testing.T) {
}
ACC {
users [{user: usr, password: pwd}]
jetstream: enabled
jetstream: {max_store: 4Mb, max_memory: 5Mb}
}
BCC_TO_HAVE_ONE_EXTRA {
users [{user: usr2, password: pwd}]
@@ -4034,6 +4034,12 @@ func TestMonitorJsz(t *testing.T) {
if info.Messages != 1 {
t.Fatalf("expected one message but got %d", info.Messages)
}
if info.ReservedStore != 4*1024*1024 {
t.Fatalf("expected 4Mb reserved, got %d bytes", info.ReservedStore)
}
if info.ReservedMemory != 5*1024*1024 {
t.Fatalf("expected 5Mb reserved, got %d bytes", info.ReservedStore)
}
}
})
t.Run("accounts", func(t *testing.T) {