Skip to content

Export account resource metrics and configuration #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions collector/jsz.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ type jszCollector struct {
maxMemory *prometheus.Desc
maxStorage *prometheus.Desc

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

// Stream stats
streamMessages *prometheus.Desc
streamBytes *prometheus.Desc
Expand Down Expand Up @@ -74,6 +80,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 +146,34 @@ 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_storage_used
accountStorage: prometheus.NewDesc(
prometheus.BuildFQName(system, "account", "storage_used"),
"Total number of bytes used by JetStream storage",
accountLabels,
nil,
),
// jetstream_account_memory_used
accountMemory: prometheus.NewDesc(
prometheus.BuildFQName(system, "account", "memory_used"),
"Total number of bytes used by JetStream memory",
accountLabels,
nil,
),
// jetstream_stream_total_messages
streamMessages: prometheus.NewDesc(
prometheus.BuildFQName(system, "stream", "total_messages"),
Expand Down Expand Up @@ -340,6 +379,20 @@ 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))
ch <- accountMetric(nc.accountMemory, float64(account.Memory))

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