Skip to content

Commit e6f55c3

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 e6f55c3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

collector/jsz.go

+46
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ 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+
4247
// Stream stats
4348
streamMessages *prometheus.Desc
4449
streamBytes *prometheus.Desc
@@ -74,6 +79,11 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet
7479
streamLabels = append(streamLabels, "is_stream_leader")
7580
streamLabels = append(streamLabels, "stream_raft_group")
7681

82+
var accountLabels []string
83+
accountLabels = append(accountLabels, serverLabels...)
84+
accountLabels = append(accountLabels, "account")
85+
accountLabels = append(accountLabels, "account_id")
86+
7787
var consumerLabels []string
7888
consumerLabels = append(consumerLabels, streamLabels...)
7989
consumerLabels = append(consumerLabels, "consumer_name")
@@ -135,6 +145,29 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet
135145
serverLabels,
136146
nil,
137147
),
148+
// jetstream_account_max_memory
149+
maxAccountMemory: prometheus.NewDesc(
150+
prometheus.BuildFQName(system, "account", "max_memory"),
151+
"JetStream Account Max Memory in bytes",
152+
accountLabels,
153+
nil,
154+
),
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+
164+
// jetstream_account_total_bytes
165+
accountStorage: prometheus.NewDesc(
166+
prometheus.BuildFQName(system, "account", "total_bytes"),
167+
"Total number of bytes stored in JetStream account",
168+
accountLabels,
169+
nil,
170+
),
138171
// jetstream_stream_total_messages
139172
streamMessages: prometheus.NewDesc(
140173
prometheus.BuildFQName(system, "stream", "total_messages"),
@@ -340,6 +373,19 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) {
340373
for _, account := range resp.AccountDetails {
341374
accountName = account.Name
342375
accountID = account.Id
376+
377+
accountMetric := func(key *prometheus.Desc, value float64) prometheus.Metric {
378+
return prometheus.MustNewConstMetric(key, prometheus.GaugeValue, value,
379+
// Server Labels
380+
serverID, serverName, clusterName, jsDomain, clusterLeader, isMetaLeader,
381+
// Account Labels
382+
accountName, accountID)
383+
}
384+
385+
ch <- accountMetric(nc.maxAccountStorage, float64(account.ReservedStore))
386+
ch <- accountMetric(nc.maxAccountMemory, float64(account.ReservedMemory))
387+
ch <- accountMetric(nc.accountStorage, float64(account.Store))
388+
343389
for _, stream := range account.Streams {
344390
streamName = stream.Name
345391
if stream.Cluster != nil {

0 commit comments

Comments
 (0)