Skip to content

Commit f005806

Browse files
authored
feat(otel): Add wait metrics to otel (#3493)
* Add wait metrics to otel * add unit
1 parent fafec3f commit f005806

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

extra/redisotel/metrics.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ func reportPoolStats(rdb *redis.Client, conf *config) (metric.Registration, erro
155155
return nil, err
156156
}
157157

158+
waits, err := conf.meter.Int64ObservableUpDownCounter(
159+
"db.client.connections.waits",
160+
metric.WithDescription("The number of times a connection was waited for"),
161+
)
162+
if err != nil {
163+
return nil, err
164+
}
165+
166+
waitsDuration, err := conf.meter.Int64ObservableUpDownCounter(
167+
"db.client.connections.waits_duration",
168+
metric.WithDescription("The total time spent for waiting a connection in nanoseconds"),
169+
metric.WithUnit("ns"),
170+
)
171+
if err != nil {
172+
return nil, err
173+
}
174+
158175
timeouts, err := conf.meter.Int64ObservableUpDownCounter(
159176
"db.client.connections.timeouts",
160177
metric.WithDescription("The number of connection timeouts that have occurred trying to obtain a connection from the pool"),
@@ -191,6 +208,9 @@ func reportPoolStats(rdb *redis.Client, conf *config) (metric.Registration, erro
191208
o.ObserveInt64(usage, int64(stats.IdleConns), metric.WithAttributeSet(idleAttrs))
192209
o.ObserveInt64(usage, int64(stats.TotalConns-stats.IdleConns), metric.WithAttributeSet(usedAttrs))
193210

211+
o.ObserveInt64(waits, int64(stats.WaitCount), metric.WithAttributeSet(poolAttrs))
212+
o.ObserveInt64(waitsDuration, stats.WaitDurationNs, metric.WithAttributeSet(poolAttrs))
213+
194214
o.ObserveInt64(timeouts, int64(stats.Timeouts), metric.WithAttributeSet(poolAttrs))
195215
o.ObserveInt64(hits, int64(stats.Hits), metric.WithAttributeSet(poolAttrs))
196216
o.ObserveInt64(misses, int64(stats.Misses), metric.WithAttributeSet(poolAttrs))

0 commit comments

Comments
 (0)