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 PromErrors prometheus.Counter
21 PromInBytes prometheus.Counter
22 PromOutBytes prometheus.Counter
23 PromErrorCodes *prometheus.CounterVec
25 ErrorCodes map[string]uint64 `json:",omitempty"`
29 // Tick increments each of the given counters by 1 using
31 func (s *statsTicker) Tick(counters ...*uint64) {
32 for _, counter := range counters {
33 atomic.AddUint64(counter, 1)
37 // TickErr increments the overall error counter, as well as the
38 // ErrorCodes entry for the given errType. If err is nil, TickErr is a
40 func (s *statsTicker) TickErr(err error, errType string) {
48 if s.ErrorCodes == nil {
49 s.ErrorCodes = make(map[string]uint64)
51 s.ErrorCodes[errType]++
53 s.PromErrorCodes.WithLabelValues(errType).Inc()
56 // TickInBytes increments the incoming byte counter by n.
57 func (s *statsTicker) TickInBytes(n uint64) {
58 s.PromInBytes.Add(float64(n))
59 atomic.AddUint64(&s.InBytes, n)
62 // TickOutBytes increments the outgoing byte counter by n.
63 func (s *statsTicker) TickOutBytes(n uint64) {
64 s.PromOutBytes.Add(float64(n))
65 atomic.AddUint64(&s.OutBytes, n)