Skip to content

Commit

Permalink
Convert some counter metrics to gauges
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Sep 28, 2023
1 parent 2b0190c commit edb66b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions pkg/metrics/api-limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import (

var bucketsNameKey = "name"

var ratelimiterBuckets = prometheus.NewCounterVec(
prometheus.CounterOpts{
var ratelimiterBuckets = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "xmtp_ratelimiter_buckets",
Help: "Size of rate-limiter buckets maps",
},
[]string{bucketsNameKey},
)

func EmitRatelimiterBucketsSize(ctx context.Context, name string, size int) {
ratelimiterBuckets.WithLabelValues(name).Add(float64(size))
ratelimiterBuckets.WithLabelValues(name).Set(float64(size))
}

var ratelimiterBucketsDeleted = prometheus.NewCounterVec(
prometheus.CounterOpts{
var ratelimiterBucketsDeleted = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "xmtp_ratelimiter_entries_deleted",
Help: "Count of deleted entries from rate-limiter buckets maps",
},
[]string{bucketsNameKey},
)

func EmitRatelimiterDeletedEntries(ctx context.Context, name string, count int) {
ratelimiterBucketsDeleted.WithLabelValues(name).Add(float64(count))
ratelimiterBucketsDeleted.WithLabelValues(name).Set(float64(count))
}
12 changes: 6 additions & 6 deletions pkg/metrics/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var PeersByProto = prometheus.NewCounterVec(
prometheus.CounterOpts{
var PeersByProto = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "xmtp_peers_by_proto",
Help: "Count of peers by protocol",
},
[]string{"protocol"},
)

var BootstrapPeers = prometheus.NewCounter(
prometheus.CounterOpts{
var BootstrapPeers = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "xmtp_bootstrap_peers",
Help: "Percentage of bootstrap peers connected",
},
Expand All @@ -37,7 +37,7 @@ func EmitPeersByProtocol(ctx context.Context, host host.Host) {
}
}
for proto, count := range byProtocol {
PeersByProto.WithLabelValues(proto).Add(float64(count))
PeersByProto.WithLabelValues(proto).Set(float64(count))
}
}

Expand All @@ -48,5 +48,5 @@ func EmitBootstrapPeersConnected(ctx context.Context, host host.Host, bootstrapP
bootstrapPeersFound++
}
}
BootstrapPeers.Add(float64(bootstrapPeersFound) / float64(len(bootstrapPeers)))
BootstrapPeers.Set(float64(bootstrapPeersFound) / float64(len(bootstrapPeers)))
}
6 changes: 3 additions & 3 deletions pkg/metrics/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"go.uber.org/zap"
)

var StoredMessages = prometheus.NewCounter(
prometheus.CounterOpts{
var StoredMessages = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "xmtp_stored_messages",
Help: "Count of stored messages",
},
Expand All @@ -21,7 +21,7 @@ func EmitStoredMessages(ctx context.Context, db *sql.DB, logger *zap.Logger) {
if err != nil {
logger.Error("counting messages", zap.Error(err))
}
StoredMessages.Add(float64(count))
StoredMessages.Set(float64(count))
}

func messageCountEstimate(db *sql.DB) (count int64, err error) {
Expand Down

0 comments on commit edb66b7

Please sign in to comment.