-
Notifications
You must be signed in to change notification settings - Fork 2
/
prometheus.go
55 lines (49 loc) · 1.33 KB
/
prometheus.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
package main
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
)
func setupPrometheusMetrics(s *stats) {
cs := []prometheus.Collector{
prometheus.NewCounterFunc(prometheus.CounterOpts{
Namespace: "go_import_server",
Subsystem: "stats",
Name: "view_total",
Help: "Number of total page views",
}, func() float64 {
return float64(s.TotalView())
}),
prometheus.NewCounterFunc(prometheus.CounterOpts{
Namespace: "go_import_server",
Subsystem: "stats",
Name: "get_total",
Help: "Number of total 'go-get's",
}, func() float64 {
return float64(s.TotalGet())
}),
}
sr := strings.NewReplacer(".", "_", "/", "_", "-", "_")
for p := range s.pkgsView {
p := p
cs = append(cs, prometheus.NewCounterFunc(prometheus.CounterOpts{
Namespace: "go_import_server",
Subsystem: "stats",
Name: "view_" + sr.Replace(p),
Help: "Number of page views for " + p,
}, func() float64 {
return float64(s.PkgView(p))
}))
}
for p := range s.pkgsGet {
p := p
cs = append(cs, prometheus.NewCounterFunc(prometheus.CounterOpts{
Namespace: "go_import_server",
Subsystem: "stats",
Name: "get_" + sr.Replace(p),
Help: "Number of 'go-get's for " + p,
}, func() float64 {
return float64(s.PkgGet(p))
}))
}
prometheus.MustRegister(cs...)
}