X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/609646134bcd8fc3a7fd500848220741ecc4a9d2..HEAD:/services/keepstore/stats_ticker.go diff --git a/services/keepstore/stats_ticker.go b/services/keepstore/stats_ticker.go index f3a79c68f3..520d4530c2 100644 --- a/services/keepstore/stats_ticker.go +++ b/services/keepstore/stats_ticker.go @@ -1,8 +1,14 @@ -package main +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +package keepstore import ( "sync" "sync/atomic" + + "github.com/prometheus/client_golang/prometheus" ) type statsTicker struct { @@ -12,6 +18,10 @@ type statsTicker struct { ErrorCodes map[string]uint64 `json:",omitempty"` lock sync.Mutex + + opsCounters *prometheus.CounterVec + errCounters *prometheus.CounterVec + ioBytes *prometheus.CounterVec } // Tick increments each of the given counters by 1 using @@ -37,14 +47,33 @@ func (s *statsTicker) TickErr(err error, errType string) { } s.ErrorCodes[errType]++ s.lock.Unlock() + if s.errCounters != nil { + 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.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.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() + } +}