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 {
20 errors prometheus.Counter
21 inBytes prometheus.Counter
22 outBytes prometheus.Counter
23 errCounters *prometheus.CounterVec
25 ErrorCodes map[string]uint64 `json:",omitempty"`
29 func (s *statsTicker) setup(m *volumeMetrics) {
31 s.errCounters = m.ErrorCodes
33 s.outBytes = m.OutBytes
36 // Tick increments each of the given counters by 1 using
38 func (s *statsTicker) Tick(counters ...*uint64) {
39 for _, counter := range counters {
40 atomic.AddUint64(counter, 1)
44 // TickErr increments the overall error counter, as well as the
45 // ErrorCodes entry for the given errType. If err is nil, TickErr is a
47 func (s *statsTicker) TickErr(err error, errType string) {
57 if s.ErrorCodes == nil {
58 s.ErrorCodes = make(map[string]uint64)
60 s.ErrorCodes[errType]++
62 if s.errCounters != nil {
63 s.errCounters.WithLabelValues(errType).Inc()
67 // TickInBytes increments the incoming byte counter by n.
68 func (s *statsTicker) TickInBytes(n uint64) {
70 s.inBytes.Add(float64(n))
72 atomic.AddUint64(&s.InBytes, n)
75 // TickOutBytes increments the outgoing byte counter by n.
76 func (s *statsTicker) TickOutBytes(n uint64) {
77 if s.outBytes != nil {
78 s.outBytes.Add(float64(n))
80 atomic.AddUint64(&s.OutBytes, n)