Warn if MaxKeepBlobBuffers > MaxConcurrentRequests.
[arvados.git] / services / keepstore / metrics.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "fmt"
9
10         "github.com/prometheus/client_golang/prometheus"
11 )
12
13 type nodeMetrics struct {
14         reg *prometheus.Registry
15 }
16
17 func (m *nodeMetrics) setupBufferPoolMetrics(b *bufferPool) {
18         m.reg.MustRegister(prometheus.NewGaugeFunc(
19                 prometheus.GaugeOpts{
20                         Namespace: "arvados",
21                         Subsystem: "keepstore",
22                         Name:      "bufferpool_allocated_bytes",
23                         Help:      "Number of bytes allocated to buffers",
24                 },
25                 func() float64 { return float64(b.Alloc()) },
26         ))
27         m.reg.MustRegister(prometheus.NewGaugeFunc(
28                 prometheus.GaugeOpts{
29                         Namespace: "arvados",
30                         Subsystem: "keepstore",
31                         Name:      "bufferpool_max_buffers",
32                         Help:      "Maximum number of buffers allowed",
33                 },
34                 func() float64 { return float64(b.Cap()) },
35         ))
36         m.reg.MustRegister(prometheus.NewGaugeFunc(
37                 prometheus.GaugeOpts{
38                         Namespace: "arvados",
39                         Subsystem: "keepstore",
40                         Name:      "bufferpool_inuse_buffers",
41                         Help:      "Number of buffers in use",
42                 },
43                 func() float64 { return float64(b.Len()) },
44         ))
45 }
46
47 func (m *nodeMetrics) setupWorkQueueMetrics(q *WorkQueue, qName string) {
48         m.reg.MustRegister(prometheus.NewGaugeFunc(
49                 prometheus.GaugeOpts{
50                         Namespace: "arvados",
51                         Subsystem: "keepstore",
52                         Name:      fmt.Sprintf("%s_queue_inprogress_entries", qName),
53                         Help:      fmt.Sprintf("Number of %s requests in progress", qName),
54                 },
55                 func() float64 { return float64(getWorkQueueStatus(q).InProgress) },
56         ))
57         m.reg.MustRegister(prometheus.NewGaugeFunc(
58                 prometheus.GaugeOpts{
59                         Namespace: "arvados",
60                         Subsystem: "keepstore",
61                         Name:      fmt.Sprintf("%s_queue_pending_entries", qName),
62                         Help:      fmt.Sprintf("Number of queued %s requests", qName),
63                 },
64                 func() float64 { return float64(getWorkQueueStatus(q).Queued) },
65         ))
66 }
67
68 type volumeMetricsVecs struct {
69         ioBytes     *prometheus.CounterVec
70         errCounters *prometheus.CounterVec
71         opsCounters *prometheus.CounterVec
72 }
73
74 func newVolumeMetricsVecs(reg *prometheus.Registry) *volumeMetricsVecs {
75         m := &volumeMetricsVecs{}
76         m.opsCounters = prometheus.NewCounterVec(
77                 prometheus.CounterOpts{
78                         Namespace: "arvados",
79                         Subsystem: "keepstore",
80                         Name:      "volume_operations",
81                         Help:      "Number of volume operations",
82                 },
83                 []string{"device_id", "operation"},
84         )
85         reg.MustRegister(m.opsCounters)
86         m.errCounters = prometheus.NewCounterVec(
87                 prometheus.CounterOpts{
88                         Namespace: "arvados",
89                         Subsystem: "keepstore",
90                         Name:      "volume_errors",
91                         Help:      "Number of volume errors",
92                 },
93                 []string{"device_id", "error_type"},
94         )
95         reg.MustRegister(m.errCounters)
96         m.ioBytes = prometheus.NewCounterVec(
97                 prometheus.CounterOpts{
98                         Namespace: "arvados",
99                         Subsystem: "keepstore",
100                         Name:      "volume_io_bytes",
101                         Help:      "Volume I/O traffic in bytes",
102                 },
103                 []string{"device_id", "direction"},
104         )
105         reg.MustRegister(m.ioBytes)
106
107         return m
108 }
109
110 func (vm *volumeMetricsVecs) getCounterVecsFor(lbls prometheus.Labels) (opsCV, errCV, ioCV *prometheus.CounterVec) {
111         opsCV = vm.opsCounters.MustCurryWith(lbls)
112         errCV = vm.errCounters.MustCurryWith(lbls)
113         ioCV = vm.ioBytes.MustCurryWith(lbls)
114         return
115 }