diff --git a/server/jetstream.go b/server/jetstream.go index f462f330..b0ea04b4 100644 --- a/server/jetstream.go +++ b/server/jetstream.go @@ -36,9 +36,16 @@ import ( // JetStreamConfig determines this server's configuration. // MaxMemory and MaxStore are in bytes. type JetStreamConfig struct { - MaxMemory int64 - MaxStore int64 - StoreDir string + MaxMemory int64 `json:"max_memory"` + MaxStore int64 `json:"max_storage"` + StoreDir string `json:"store_dir,omitempty"` +} + +type JetStreamStats struct { + Memory uint64 `json:"memory"` + Store uint64 `json:"storage"` + Accounts int `json:"accounts,omitempty"` + API JetStreamAPIStats `json:"api"` } type JetStreamAccountLimits struct { @@ -1153,6 +1160,33 @@ func (js *jetStream) dynamicAccountLimits() *JetStreamAccountLimits { return limits } +// Report on JetStream stats and usage. +func (js *jetStream) usageStats() *JetStreamStats { + var stats JetStreamStats + + var _jsa [512]*jsAccount + accounts := _jsa[:0] + + js.mu.RLock() + for _, jsa := range js.accounts { + accounts = append(accounts, jsa) + } + js.mu.RUnlock() + + stats.Accounts = len(accounts) + + // Collect account information. + for _, jsa := range accounts { + jsa.mu.RLock() + stats.Memory += uint64(jsa.memTotal) + stats.Store += uint64(jsa.storeTotal) + stats.API.Total += jsa.apiTotal + stats.API.Errors += jsa.apiErrors + jsa.mu.RUnlock() + } + return &stats +} + // Check to see if we have enough system resources for this account. // Lock should be held. func (js *jetStream) sufficientResources(limits *JetStreamAccountLimits) error { diff --git a/server/monitor.go b/server/monitor.go index 4bbeb70a..fc17201b 100644 --- a/server/monitor.go +++ b/server/monitor.go @@ -1051,10 +1051,8 @@ type Varz struct { // JetStreamVarz contains basic runtime information about jetstream type JetStreamVarz struct { - MaxMemory int64 `json:"max_memory,omitempty"` - MaxStore int64 `json:"max_store,omitempty"` - StoreDir string `json:"store_dir,omitempty"` - Accounts int `json:"accounts,omitempty"` + Config JetStreamConfig `json:"config"` + Stats *JetStreamStats `json:"stats"` } // ClusterOptsVarz contains monitoring cluster information @@ -1288,9 +1286,7 @@ func (s *Server) createVarz(pcpu float64, rss int64) *Varz { if s.js != nil { s.js.mu.RLock() varz.JetStream = JetStreamVarz{ - MaxMemory: s.js.config.MaxMemory, - MaxStore: s.js.config.MaxStore, - StoreDir: s.js.config.StoreDir, + Config: s.js.config, } s.js.mu.RUnlock() } @@ -1403,9 +1399,7 @@ func (s *Server) updateVarzRuntimeFields(v *Varz, forceUpdate bool, pcpu float64 gw.RUnlock() if s.js != nil { - s.js.mu.RLock() - v.JetStream.Accounts = len(s.js.accounts) - s.js.mu.RUnlock() + v.JetStream.Stats = s.js.usageStats() } }