Initial commit

This commit is contained in:
Yaser
2026-08-13 20:20:47 +03:30
commit 78a0c832d7
33 changed files with 3399 additions and 0 deletions

63
pkg/metrics/metrics.go Normal file
View File

@@ -0,0 +1,63 @@
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var defaultMetrics *Metrics
type Metrics struct {
clients prometheus.Gauge
subs *prometheus.GaugeVec
}
func Enable() {
defaultMetrics = &Metrics{}
registerMetrics()
}
func registerMetrics() {
defaultMetrics.clients = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "rango_hub_clients_count",
Help: "Number of clients currently connected",
},
)
defaultMetrics.subs = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "rango_hub_subscriptions_count",
Help: "Number of user subscribed to a topic",
},
[]string{"type", "topic"},
)
}
func RecordHubClientNew() {
if defaultMetrics == nil {
return
}
defaultMetrics.clients.Inc()
}
func RecordHubClientClose() {
if defaultMetrics == nil {
return
}
defaultMetrics.clients.Dec()
}
func RecordHubSubscription(typ, topic string) {
if defaultMetrics == nil {
return
}
defaultMetrics.subs.WithLabelValues(typ, topic).Inc()
}
func RecordHubUnsubscription(typ, topic string) {
if defaultMetrics == nil {
return
}
defaultMetrics.subs.WithLabelValues(typ, topic).Dec()
}