-
Notifications
You must be signed in to change notification settings - Fork 1
/
metrics.go
66 lines (53 loc) · 1.46 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
package gitserver
import (
"net/http"
"runtime"
base "github.com/omegaup/go-base/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
gauges = map[string]prometheus.Gauge{}
counters = map[string]prometheus.Counter{}
summaries = map[string]prometheus.Summary{}
)
type prometheusMetrics struct {
}
func (p *prometheusMetrics) GaugeAdd(name string, value float64) {
if gauge, ok := gauges[name]; ok {
gauge.Add(value)
}
}
func (p *prometheusMetrics) CounterAdd(name string, value float64) {
if counter, ok := counters[name]; ok {
counter.Add(value)
}
}
func (p *prometheusMetrics) SummaryObserve(name string, value float64) {
if summary, ok := summaries[name]; ok {
summary.Observe(value)
}
}
// SetupMetrics sets up the metrics for the gitserver.
func SetupMetrics(programVersion string) (base.Metrics, http.Handler) {
for _, gauge := range gauges {
prometheus.MustRegister(gauge)
}
for _, counter := range counters {
prometheus.MustRegister(counter)
}
for _, summary := range summaries {
prometheus.MustRegister(summary)
}
buildInfoCounter := prometheus.NewCounter(prometheus.CounterOpts{
Help: "Information about the build",
Name: "build_info",
ConstLabels: prometheus.Labels{
"go_version": runtime.Version(),
"version": programVersion,
},
})
prometheus.MustRegister(buildInfoCounter)
buildInfoCounter.Inc()
return &prometheusMetrics{}, promhttp.Handler()
}