diff --git a/internal/server/expire.go b/internal/server/expire.go index 5f812913..afce8c49 100644 --- a/internal/server/expire.go +++ b/internal/server/expire.go @@ -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 }) diff --git a/internal/server/metrics.go b/internal/server/metrics.go index 78133ceb..b33bf15a 100644 --- a/internal/server/metrics.go +++ b/internal/server/metrics.go @@ -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 +}