1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "github.com/prometheus/client_golang/prometheus"
15 type statsTicker struct {
20 ErrorCodes map[string]uint64 `json:",omitempty"`
24 func (s *statsTicker) setupPrometheus(drv string, reg *prometheus.Registry, lbl prometheus.Labels) {
25 metrics := map[string][]interface{}{
26 "errors": []interface{}{string("errors"), s.Errors},
27 "in_bytes": []interface{}{string("input bytes"), s.InBytes},
28 "out_bytes": []interface{}{string("output bytes"), s.OutBytes},
30 for mName, data := range metrics {
31 mHelp := data[0].(string)
32 mVal := data[1].(uint64)
33 reg.Register(prometheus.NewGaugeFunc(
36 Subsystem: "keepstore",
37 Name: fmt.Sprintf("%s_%s", drv, mName),
38 Help: fmt.Sprintf("Number of %s backend %s", drv, mHelp),
41 func() float64 { return float64(mVal) },
46 // Tick increments each of the given counters by 1 using
48 func (s *statsTicker) Tick(counters ...*uint64) {
49 for _, counter := range counters {
50 atomic.AddUint64(counter, 1)
54 // TickErr increments the overall error counter, as well as the
55 // ErrorCodes entry for the given errType. If err is nil, TickErr is a
57 func (s *statsTicker) TickErr(err error, errType string) {
64 if s.ErrorCodes == nil {
65 s.ErrorCodes = make(map[string]uint64)
67 s.ErrorCodes[errType]++
71 // TickInBytes increments the incoming byte counter by n.
72 func (s *statsTicker) TickInBytes(n uint64) {
73 atomic.AddUint64(&s.InBytes, n)
76 // TickOutBytes increments the outgoing byte counter by n.
77 func (s *statsTicker) TickOutBytes(n uint64) {
78 atomic.AddUint64(&s.OutBytes, n)