1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/net/streampool/metric.go
2024-08-11 17:34:24 +02:00

36 lines
944 B
Go

package streampool
import "github.com/prometheus/client_golang/prometheus"
func registerMetrics(ref *prometheus.Registry, sp *streamPool, name string) {
ref.MustRegister(
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: name,
Subsystem: "streampool",
Name: "stream_count",
Help: "count of opened streams",
}, func() float64 {
sp.mu.Lock()
defer sp.mu.Unlock()
return float64(len(sp.streams))
}),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: name,
Subsystem: "streampool",
Name: "tag_count",
Help: "count of active tags",
}, func() float64 {
sp.mu.Lock()
defer sp.mu.Unlock()
return float64(len(sp.streamIdsByTag))
}),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: name,
Subsystem: "streampool",
Name: "dial_queue",
Help: "dial queue size",
}, func() float64 {
return float64(sp.dial.batch.Len())
}),
)
}