1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

feat: add more stats for otel (#2930)

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
This commit is contained in:
fengyun.rui
2025-05-07 16:14:48 +08:00
committed by GitHub
parent 6d788cbcd4
commit 4cedb5c037

View File

@ -127,6 +127,22 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
return err
}
hits, err := conf.meter.Int64ObservableUpDownCounter(
"db.client.connections.hits",
metric.WithDescription("The number of times free connection was found in the pool"),
)
if err != nil {
return err
}
misses, err := conf.meter.Int64ObservableUpDownCounter(
"db.client.connections.misses",
metric.WithDescription("The number of times free connection was not found in the pool"),
)
if err != nil {
return err
}
redisConf := rdb.Options()
_, err = conf.meter.RegisterCallback(
func(ctx context.Context, o metric.Observer) error {
@ -140,6 +156,8 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
o.ObserveInt64(usage, int64(stats.TotalConns-stats.IdleConns), metric.WithAttributes(usedAttrs...))
o.ObserveInt64(timeouts, int64(stats.Timeouts), metric.WithAttributes(labels...))
o.ObserveInt64(hits, int64(stats.Hits), metric.WithAttributes(labels...))
o.ObserveInt64(misses, int64(stats.Misses), metric.WithAttributes(labels...))
return nil
},
idleMax,
@ -147,6 +165,8 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
connsMax,
usage,
timeouts,
hits,
misses,
)
return err