@@ -113,10 +113,15 @@ func registerClient(rdb *redis.Client, conf *config, state *metricsState) error
113
113
return nil
114
114
}
115
115
116
+ func poolStatsAttrs (conf * config ) (poolAttrs , idleAttrs , usedAttrs attribute.Set ) {
117
+ poolAttrs = attribute .NewSet (conf .attrs ... )
118
+ idleAttrs = attribute .NewSet (append (poolAttrs .ToSlice (), attribute .String ("state" , "idle" ))... )
119
+ usedAttrs = attribute .NewSet (append (poolAttrs .ToSlice (), attribute .String ("state" , "used" ))... )
120
+ return
121
+ }
122
+
116
123
func reportPoolStats (rdb * redis.Client , conf * config ) (metric.Registration , error ) {
117
- labels := conf .attrs
118
- idleAttrs := append (labels , attribute .String ("state" , "idle" ))
119
- usedAttrs := append (labels , attribute .String ("state" , "used" ))
124
+ poolAttrs , idleAttrs , usedAttrs := poolStatsAttrs (conf )
120
125
121
126
idleMax , err := conf .meter .Int64ObservableUpDownCounter (
122
127
"db.client.connections.idle.max" ,
@@ -179,16 +184,16 @@ func reportPoolStats(rdb *redis.Client, conf *config) (metric.Registration, erro
179
184
func (ctx context.Context , o metric.Observer ) error {
180
185
stats := rdb .PoolStats ()
181
186
182
- o .ObserveInt64 (idleMax , int64 (redisConf .MaxIdleConns ), metric .WithAttributes ( labels ... ))
183
- o .ObserveInt64 (idleMin , int64 (redisConf .MinIdleConns ), metric .WithAttributes ( labels ... ))
184
- o .ObserveInt64 (connsMax , int64 (redisConf .PoolSize ), metric .WithAttributes ( labels ... ))
187
+ o .ObserveInt64 (idleMax , int64 (redisConf .MaxIdleConns ), metric .WithAttributeSet ( poolAttrs ))
188
+ o .ObserveInt64 (idleMin , int64 (redisConf .MinIdleConns ), metric .WithAttributeSet ( poolAttrs ))
189
+ o .ObserveInt64 (connsMax , int64 (redisConf .PoolSize ), metric .WithAttributeSet ( poolAttrs ))
185
190
186
- o .ObserveInt64 (usage , int64 (stats .IdleConns ), metric .WithAttributes (idleAttrs ... ))
187
- o .ObserveInt64 (usage , int64 (stats .TotalConns - stats .IdleConns ), metric .WithAttributes (usedAttrs ... ))
191
+ o .ObserveInt64 (usage , int64 (stats .IdleConns ), metric .WithAttributeSet (idleAttrs ))
192
+ o .ObserveInt64 (usage , int64 (stats .TotalConns - stats .IdleConns ), metric .WithAttributeSet (usedAttrs ))
188
193
189
- o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), metric .WithAttributes ( labels ... ))
190
- o .ObserveInt64 (hits , int64 (stats .Hits ), metric .WithAttributes ( labels ... ))
191
- o .ObserveInt64 (misses , int64 (stats .Misses ), metric .WithAttributes ( labels ... ))
194
+ o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), metric .WithAttributeSet ( poolAttrs ))
195
+ o .ObserveInt64 (hits , int64 (stats .Hits ), metric .WithAttributeSet ( poolAttrs ))
196
+ o .ObserveInt64 (misses , int64 (stats .Misses ), metric .WithAttributeSet ( poolAttrs ))
192
197
return nil
193
198
},
194
199
idleMax ,
0 commit comments