Skip to content

Commit 27340d1

Browse files
committed
Collect account resource consumption and settings
Adds three new metrics that collects configured reserved memory and storage along with how many bytes are currently used.
1 parent 86f1a53 commit 27340d1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

collector/jsz.go

+53
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ type jszCollector struct {
3939
maxMemory *prometheus.Desc
4040
maxStorage *prometheus.Desc
4141

42+
// Account stats
43+
maxAccountMemory *prometheus.Desc
44+
maxAccountStorage *prometheus.Desc
45+
accountStorage *prometheus.Desc
46+
accountMemory *prometheus.Desc
47+
4248
// Stream stats
4349
streamMessages *prometheus.Desc
4450
streamBytes *prometheus.Desc
@@ -74,6 +80,11 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet
7480
streamLabels = append(streamLabels, "is_stream_leader")
7581
streamLabels = append(streamLabels, "stream_raft_group")
7682

83+
var accountLabels []string
84+
accountLabels = append(accountLabels, serverLabels...)
85+
accountLabels = append(accountLabels, "account")
86+
accountLabels = append(accountLabels, "account_id")
87+
7788
var consumerLabels []string
7889
consumerLabels = append(consumerLabels, streamLabels...)
7990
consumerLabels = append(consumerLabels, "consumer_name")
@@ -135,6 +146,34 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet
135146
serverLabels,
136147
nil,
137148
),
149+
// jetstream_account_max_memory
150+
maxAccountMemory: prometheus.NewDesc(
151+
prometheus.BuildFQName(system, "account", "max_memory"),
152+
"JetStream Account Max Memory in bytes",
153+
accountLabels,
154+
nil,
155+
),
156+
// jetstream_account_max_storage
157+
maxAccountStorage: prometheus.NewDesc(
158+
prometheus.BuildFQName(system, "account", "max_storage"),
159+
"JetStream Account Max Storage in bytes",
160+
accountLabels,
161+
nil,
162+
),
163+
// jetstream_account_storage_used
164+
accountStorage: prometheus.NewDesc(
165+
prometheus.BuildFQName(system, "account", "storage_used"),
166+
"Total number of bytes used by JetStream storage",
167+
accountLabels,
168+
nil,
169+
),
170+
// jetstream_account_memory_used
171+
accountMemory: prometheus.NewDesc(
172+
prometheus.BuildFQName(system, "account", "memory_used"),
173+
"Total number of bytes used by JetStream memory",
174+
accountLabels,
175+
nil,
176+
),
138177
// jetstream_stream_total_messages
139178
streamMessages: prometheus.NewDesc(
140179
prometheus.BuildFQName(system, "stream", "total_messages"),
@@ -340,6 +379,20 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) {
340379
for _, account := range resp.AccountDetails {
341380
accountName = account.Name
342381
accountID = account.Id
382+
383+
accountMetric := func(key *prometheus.Desc, value float64) prometheus.Metric {
384+
return prometheus.MustNewConstMetric(key, prometheus.GaugeValue, value,
385+
// Server Labels
386+
serverID, serverName, clusterName, jsDomain, clusterLeader, isMetaLeader,
387+
// Account Labels
388+
accountName, accountID)
389+
}
390+
391+
ch <- accountMetric(nc.maxAccountStorage, float64(account.ReservedStore))
392+
ch <- accountMetric(nc.maxAccountMemory, float64(account.ReservedMemory))
393+
ch <- accountMetric(nc.accountStorage, float64(account.Store))
394+
ch <- accountMetric(nc.accountMemory, float64(account.Memory))
395+
343396
for _, stream := range account.Streams {
344397
streamName = stream.Name
345398
if stream.Cluster != nil {

0 commit comments

Comments
 (0)