-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
83 lines (80 loc) · 2.7 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
package rtfblog
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type metrics struct {
registry *prometheus.Registry
numRobotsServed prometheus.Counter
numForbiddenResponses prometheus.Counter
numAdminRequests prometheus.Counter
numNonAdminRequests prometheus.Counter
numPanics prometheus.Counter
numInternalErrors prometheus.Counter
latenciesHist prometheus.Histogram
}
func initMetrics() metrics {
reg := prometheus.NewRegistry()
factory := promauto.With(reg)
numRobotsServed := factory.NewCounter(prometheus.CounterOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "num_robots_txt_served",
Help: "The total number of times robots.txt was served",
})
numForbiddenResponses := factory.NewCounter(prometheus.CounterOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "num_403s",
Help: "The total number of Forbidden responses",
})
numAdminRequests := factory.NewCounter(prometheus.CounterOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "num_admin_reqs",
Help: "The total number of requests to admin area",
})
numNonAdminRequests := factory.NewCounter(prometheus.CounterOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "num_non_admin_reqs",
Help: "The total number of requests to public pages",
})
numPanics := factory.NewCounter(prometheus.CounterOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "num_panics",
Help: "The total number of panics in the handler",
})
numInternalErrors := factory.NewCounter(prometheus.CounterOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "num_internal_errors",
Help: "The total number of internal errors in the handler",
})
latenciesHist := factory.NewHistogram(prometheus.HistogramOpts{
Namespace: "rtfblog",
Subsystem: "server",
Name: "request_duration",
Help: "The time it took to serve each request",
// 0.1ms, 2x on each bucket, 16 buckets
Buckets: prometheus.ExponentialBuckets(1e-4, 2, 16),
})
procCollector := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{
Namespace: "rtfblog",
})
goCollector := collectors.NewGoCollector()
reg.Register(procCollector)
reg.Register(goCollector)
return metrics{
registry: reg,
numRobotsServed: numRobotsServed,
numForbiddenResponses: numForbiddenResponses,
numAdminRequests: numAdminRequests,
numNonAdminRequests: numNonAdminRequests,
numPanics: numPanics,
numInternalErrors: numInternalErrors,
latenciesHist: latenciesHist,
}
}