/
metrics.go
73 lines (67 loc) · 2.52 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
package server
import (
"github.com/gofiber/fiber/v2"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttpadaptor"
)
type Metrics struct {
handler fasthttp.RequestHandler
totalLogins prometheus.Counter
totalFailedLogins prometheus.Counter
totalHydraLogins prometheus.Counter
totalHydraFailedLogins prometheus.Counter
totalSignups prometheus.Counter
totalPasswordResets prometheus.Counter
totalPasswordResetsSent prometheus.Counter
totalAccountVerifications prometheus.Counter
totalAccountVerificationsSent prometheus.Counter
}
func NewMetrics() *Metrics {
m := &Metrics{
totalLogins: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_logins_total",
Help: "The total number of successful logins",
}),
totalFailedLogins: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_logins_failed_total",
Help: "The total number of failed logins",
}),
totalHydraLogins: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_hydra_logins_total",
Help: "The total number of successful Hydra logins",
}),
totalHydraFailedLogins: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_hydra_logins_failed_total",
Help: "The total number of failed Hydra logins",
}),
totalSignups: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_signups_total",
Help: "The total number of new accounts created",
}),
totalPasswordResets: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_password_reset_total",
Help: "The total number of successfull password resets",
}),
totalPasswordResetsSent: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_password_reset_sent_total",
Help: "The total number of password reset emails sent",
}),
totalAccountVerifications: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_account_verification_total",
Help: "The total number of successfull account verifications",
}),
totalAccountVerificationsSent: promauto.NewCounter(prometheus.CounterOpts{
Name: "mokey_account_verification_sent_total",
Help: "The total number of account verification emails sent",
}),
}
m.handler = fasthttpadaptor.NewFastHTTPHandler(promhttp.Handler())
return m
}
func (m *Metrics) Handler(c *fiber.Ctx) error {
m.handler(c.Context())
return nil
}