X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f50aff88ccf1ce6e590a3fe98689eabef4ad292a..b4be060bb0ee42281fc3a044c60d2b55c74475f8:/services/keepstore/stats_ticker.go diff --git a/services/keepstore/stats_ticker.go b/services/keepstore/stats_ticker.go index a9f24744b3..342b9e3205 100644 --- a/services/keepstore/stats_ticker.go +++ b/services/keepstore/stats_ticker.go @@ -16,21 +16,12 @@ type statsTicker struct { InBytes uint64 OutBytes uint64 - // Prometheus metrics - errors prometheus.Counter - inBytes prometheus.Counter - outBytes prometheus.Counter - errCounters *prometheus.CounterVec - ErrorCodes map[string]uint64 `json:",omitempty"` lock sync.Mutex -} -func (s *statsTicker) setup(m *volumeMetrics) { - s.errors = m.Errors - s.errCounters = m.ErrorCodes - s.inBytes = m.InBytes - s.outBytes = m.OutBytes + opsCounters *prometheus.CounterVec + errCounters *prometheus.CounterVec + ioBytes *prometheus.CounterVec } // Tick increments each of the given counters by 1 using @@ -48,9 +39,6 @@ func (s *statsTicker) TickErr(err error, errType string) { if err == nil { return } - if s.errors != nil { - s.errors.Inc() - } s.Tick(&s.Errors) s.lock.Lock() @@ -60,22 +48,32 @@ func (s *statsTicker) TickErr(err error, errType string) { s.ErrorCodes[errType]++ s.lock.Unlock() if s.errCounters != nil { - s.errCounters.WithLabelValues(errType).Inc() + s.errCounters.With(prometheus.Labels{"error_type": errType}).Inc() } } // TickInBytes increments the incoming byte counter by n. func (s *statsTicker) TickInBytes(n uint64) { - if s.inBytes != nil { - s.inBytes.Add(float64(n)) + if s.ioBytes != nil { + s.ioBytes.With(prometheus.Labels{"direction": "in"}).Add(float64(n)) } atomic.AddUint64(&s.InBytes, n) } // TickOutBytes increments the outgoing byte counter by n. func (s *statsTicker) TickOutBytes(n uint64) { - if s.outBytes != nil { - s.outBytes.Add(float64(n)) + if s.ioBytes != nil { + s.ioBytes.With(prometheus.Labels{"direction": "out"}).Add(float64(n)) } atomic.AddUint64(&s.OutBytes, n) } + +// TickOps increments the counter of the listed operations by 1. +func (s *statsTicker) TickOps(operations ...string) { + if s.opsCounters == nil { + return + } + for _, opType := range operations { + s.opsCounters.With(prometheus.Labels{"operation": opType}).Inc() + } +}