1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "github.com/prometheus/client_golang/prometheus"
14 type statsTicker struct {
19 ErrorCodes map[string]uint64 `json:",omitempty"`
22 opsCounters *prometheus.CounterVec
23 errCounters *prometheus.CounterVec
24 ioBytes *prometheus.CounterVec
27 // Tick increments each of the given counters by 1 using
29 func (s *statsTicker) Tick(counters ...*uint64) {
30 for _, counter := range counters {
31 atomic.AddUint64(counter, 1)
35 // TickErr increments the overall error counter, as well as the
36 // ErrorCodes entry for the given errType. If err is nil, TickErr is a
38 func (s *statsTicker) TickErr(err error, errType string) {
45 if s.ErrorCodes == nil {
46 s.ErrorCodes = make(map[string]uint64)
48 s.ErrorCodes[errType]++
50 if s.errCounters != nil {
51 s.errCounters.With(prometheus.Labels{"error_type": errType}).Inc()
55 // TickInBytes increments the incoming byte counter by n.
56 func (s *statsTicker) TickInBytes(n uint64) {
58 s.ioBytes.With(prometheus.Labels{"direction": "in"}).Add(float64(n))
60 atomic.AddUint64(&s.InBytes, n)
63 // TickOutBytes increments the outgoing byte counter by n.
64 func (s *statsTicker) TickOutBytes(n uint64) {
66 s.ioBytes.With(prometheus.Labels{"direction": "out"}).Add(float64(n))
68 atomic.AddUint64(&s.OutBytes, n)
71 // TickOps increments the counter of the listed operations by 1.
72 func (s *statsTicker) TickOps(operations ...string) {
73 if s.opsCounters == nil {
76 for _, opType := range operations {
77 s.opsCounters.With(prometheus.Labels{"operation": opType}).Inc()