Merge pull request #718 from undeadcat/bugfix-expired-metric-not-returned

fix #717: tile38_expired_keys and several other metrics not returned
This commit is contained in:
Josh Baker 2024-02-14 21:17:32 -07:00 committed by GitHub
commit a75ea8808c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 7 deletions

View File

@ -32,6 +32,7 @@ func (s *Server) backgroundExpireObjects(now time.Time) {
if nano < o.Expires() {
return false
}
s.statsExpired.Add(1)
msgs = append(msgs, &Message{Args: []string{"del", key, o.ID()}})
return true
})

View File

@ -92,13 +92,7 @@ func (s *Server) Collect(ch chan<- prometheus.Metric) {
s.extStats(m)
for metric, descr := range metricDescriptions {
val, ok := m[metric].(float64)
if !ok {
val2, ok2 := m[metric].(int)
if ok2 {
val, ok = float64(val2), true
}
}
val, ok := toFloat(m[metric])
if ok {
ch <- prometheus.MustNewConstMetric(descr, prometheus.GaugeValue, val)
}
@ -155,3 +149,31 @@ func (s *Server) Collect(ch chan<- prometheus.Metric) {
return true
})
}
func toFloat(val interface{}) (float64, bool) {
switch v := val.(type) {
case float64:
return v, true
case int64:
return float64(v), true
case uint64:
return float64(v), true
case float32:
return float64(v), true
case int:
return float64(v), true
case int32:
return float64(v), true
case uint32:
return float64(v), true
case int16:
return float64(v), true
case uint16:
return float64(v), true
case int8:
return float64(v), true
case uint8:
return float64(v), true
}
return 0, false
}