-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmetrics.go
147 lines (132 loc) · 3.5 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"runtime/debug"
"time"
"github.com/prometheus/client_golang/prometheus"
)
// - RPC requests by method (counter)
// - Epochs available epoch_available{epoch="200"} = 1
// - status_code
// - miner ids
// - source type (ipfs/bitwarden/s3/etc)
// - response time histogram
func init() {
prometheus.MustRegister(metrics_RpcRequestByMethod)
prometheus.MustRegister(metrics_epochsAvailable)
prometheus.MustRegister(metrics_statusCode)
prometheus.MustRegister(metrics_methodToCode)
prometheus.MustRegister(metrics_methodToSuccessOrFailure)
prometheus.MustRegister(metrics_methodToNumProxied)
prometheus.MustRegister(metrics_responseTimeHistogram)
}
var metrics_RpcRequestByMethod = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "rpc_requests_by_method",
Help: "RPC requests by method",
},
[]string{"method"},
)
var metrics_epochsAvailable = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "epoch_available",
Help: "Epochs available",
},
[]string{"epoch"},
)
var metrics_statusCode = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "status_code",
Help: "Status code",
},
[]string{"code"},
)
var metrics_methodToCode = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_code",
Help: "Method to code",
},
[]string{"method", "code"},
)
var metrics_methodToSuccessOrFailure = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_success_or_failure",
Help: "Method to success or failure",
},
[]string{"method", "status"},
)
var metrics_methodToNumProxied = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_num_proxied",
Help: "Method to num proxied",
},
[]string{"method"},
)
var metrics_responseTimeHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "response_time_histogram",
Help: "Response time histogram",
},
[]string{"method"},
)
// - Version information of this binary
var metrics_version = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "version",
Help: "Version information of this binary",
},
[]string{"started_at", "tag", "commit", "compiler", "goarch", "goos", "goamd64", "vcs", "vcs_revision", "vcs_time", "vcs_modified"},
)
func init() {
// Add an entry to the metric with the version information.
labeledValues := map[string]string{
"started_at": StartedAt.Format(time.RFC3339),
"tag": GitTag,
"commit": GitCommit,
"compiler": "",
"goarch": "",
"goos": "",
"goamd64": "",
"vcs": "",
"vcs_revision": "",
"vcs_time": "",
"vcs_modified": "",
}
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if isAnyOf(setting.Key,
"-compiler",
"GOARCH",
"GOOS",
"GOAMD64",
"vcs",
"vcs.revision",
"vcs.time",
"vcs.modified",
) {
switch setting.Key {
case "-compiler":
labeledValues["compiler"] = setting.Value
case "GOARCH":
labeledValues["goarch"] = setting.Value
case "GOOS":
labeledValues["goos"] = setting.Value
case "GOAMD64":
labeledValues["goamd64"] = setting.Value
case "vcs":
labeledValues["vcs"] = setting.Value
case "vcs.revision":
labeledValues["vcs_revision"] = setting.Value
case "vcs.time":
labeledValues["vcs_time"] = setting.Value
case "vcs.modified":
labeledValues["vcs_modified"] = setting.Value
}
}
}
}
metrics_version.With(labeledValues).Set(1)
}
var StartedAt = time.Now()
func GetUptime() time.Duration {
return time.Since(StartedAt)
}