Skip to content

Commit

Permalink
Collect account resource consumption and settings
Browse files Browse the repository at this point in the history
Adds three new metrics that collects configured reserved memory and storage along with how many bytes are currently used.
  • Loading branch information
MattiasAng committed Dec 10, 2024
1 parent 86f1a53 commit e6f55c3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions collector/jsz.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ type jszCollector struct {
maxMemory *prometheus.Desc
maxStorage *prometheus.Desc

// Account stats
maxAccountMemory *prometheus.Desc
maxAccountStorage *prometheus.Desc
accountStorage *prometheus.Desc

// Stream stats
streamMessages *prometheus.Desc
streamBytes *prometheus.Desc
Expand Down Expand Up @@ -74,6 +79,11 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet
streamLabels = append(streamLabels, "is_stream_leader")
streamLabels = append(streamLabels, "stream_raft_group")

var accountLabels []string
accountLabels = append(accountLabels, serverLabels...)
accountLabels = append(accountLabels, "account")
accountLabels = append(accountLabels, "account_id")

var consumerLabels []string
consumerLabels = append(consumerLabels, streamLabels...)
consumerLabels = append(consumerLabels, "consumer_name")
Expand Down Expand Up @@ -135,6 +145,29 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet
serverLabels,
nil,
),
// jetstream_account_max_memory
maxAccountMemory: prometheus.NewDesc(
prometheus.BuildFQName(system, "account", "max_memory"),
"JetStream Account Max Memory in bytes",
accountLabels,
nil,
),

// jetstream_account_max_storage
maxAccountStorage: prometheus.NewDesc(
prometheus.BuildFQName(system, "account", "max_storage"),
"JetStream Account Max Storage in bytes",
accountLabels,
nil,
),

// jetstream_account_total_bytes
accountStorage: prometheus.NewDesc(
prometheus.BuildFQName(system, "account", "total_bytes"),
"Total number of bytes stored in JetStream account",
accountLabels,
nil,
),
// jetstream_stream_total_messages
streamMessages: prometheus.NewDesc(
prometheus.BuildFQName(system, "stream", "total_messages"),
Expand Down Expand Up @@ -340,6 +373,19 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) {
for _, account := range resp.AccountDetails {
accountName = account.Name
accountID = account.Id

accountMetric := func(key *prometheus.Desc, value float64) prometheus.Metric {
return prometheus.MustNewConstMetric(key, prometheus.GaugeValue, value,
// Server Labels
serverID, serverName, clusterName, jsDomain, clusterLeader, isMetaLeader,
// Account Labels
accountName, accountID)
}

ch <- accountMetric(nc.maxAccountStorage, float64(account.ReservedStore))
ch <- accountMetric(nc.maxAccountMemory, float64(account.ReservedMemory))
ch <- accountMetric(nc.accountStorage, float64(account.Store))

for _, stream := range account.Streams {
streamName = stream.Name
if stream.Cluster != nil {
Expand Down

0 comments on commit e6f55c3

Please sign in to comment.