forked from restic/rest-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
metrics.go
92 lines (81 loc) · 2.51 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package restserver
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/restic/rest-server/repo"
)
var metricLabelList = []string{"user", "repo", "type"}
var metricBlobWriteTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rest_server_blob_write_total",
Help: "Total number of blobs written",
},
metricLabelList,
)
var metricBlobWriteBytesTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rest_server_blob_write_bytes_total",
Help: "Total number of bytes written to blobs",
},
metricLabelList,
)
var metricBlobReadTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rest_server_blob_read_total",
Help: "Total number of blobs read",
},
metricLabelList,
)
var metricBlobReadBytesTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rest_server_blob_read_bytes_total",
Help: "Total number of bytes read from blobs",
},
metricLabelList,
)
var metricBlobDeleteTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rest_server_blob_delete_total",
Help: "Total number of blobs deleted",
},
metricLabelList,
)
var metricBlobDeleteBytesTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rest_server_blob_delete_bytes_total",
Help: "Total number of bytes of blobs deleted",
},
metricLabelList,
)
// makeBlobMetricFunc creates a metrics callback function that increments the
// Prometheus metrics.
func makeBlobMetricFunc(username string, folderPath []string) repo.BlobMetricFunc {
var f repo.BlobMetricFunc = func(objectType string, operation repo.BlobOperation, nBytes uint64) {
labels := prometheus.Labels{
"user": username,
"repo": strings.Join(folderPath, "/"),
"type": objectType,
}
switch operation {
case repo.BlobRead:
metricBlobReadTotal.With(labels).Inc()
metricBlobReadBytesTotal.With(labels).Add(float64(nBytes))
case repo.BlobWrite:
metricBlobWriteTotal.With(labels).Inc()
metricBlobWriteBytesTotal.With(labels).Add(float64(nBytes))
case repo.BlobDelete:
metricBlobDeleteTotal.With(labels).Inc()
metricBlobDeleteBytesTotal.With(labels).Add(float64(nBytes))
}
}
return f
}
func init() {
// These are always initialized, but only updated if Config.Prometheus is set
prometheus.MustRegister(metricBlobWriteTotal)
prometheus.MustRegister(metricBlobWriteBytesTotal)
prometheus.MustRegister(metricBlobReadTotal)
prometheus.MustRegister(metricBlobReadBytesTotal)
prometheus.MustRegister(metricBlobDeleteTotal)
prometheus.MustRegister(metricBlobDeleteBytesTotal)
}