-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subscribed topics gauge metric (#339)
* Add subscribe/unsubscribe gauge metric * Emit unsubscribe in defer
- Loading branch information
Steven Normore
authored
Jan 23, 2024
1 parent
a15ebd3
commit becf56a
Showing
4 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var subscribedTopics = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "xmtp_subscribed_topics", | ||
Help: "Number of subscribed topics", | ||
}, | ||
appClientVersionTagKeys, | ||
) | ||
|
||
var subscribeTopicsLength = prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Name: "xmtp_subscribe_topics_length", | ||
Help: "Number of subscribed topics per request", | ||
Buckets: []float64{1, 2, 4, 8, 16, 50, 100, 10000, 100000}, | ||
}, | ||
appClientVersionTagKeys, | ||
) | ||
|
||
func EmitSubscribeTopics(ctx context.Context, log *zap.Logger, topics int) { | ||
labels := contextLabels(ctx) | ||
subscribeTopicsLength.With(labels).Observe(float64(topics)) | ||
subscribedTopics.With(labels).Add(float64(topics)) | ||
} | ||
|
||
func EmitUnsubscribeTopics(ctx context.Context, log *zap.Logger, topics int) { | ||
labels := contextLabels(ctx) | ||
subscribedTopics.With(labels).Add(-float64(topics)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters