1package metrics
2
3import (
4 "github.com/prometheus/client_golang/prometheus"
5 "github.com/prometheus/client_golang/prometheus/promauto"
6)
7
8var (
9 metricAuth = promauto.NewCounterVec(
10 prometheus.CounterOpts{
11 Name: "mox_authentication_total",
12 Help: "Authentication attempts and results.",
13 },
14 []string{
15 "kind", // submission, imap, webmail, webaccount, webadmin (formerly httpaccount, httpadmin)
16 "variant", // login, plain, scram-sha-256, scram-sha-1, cram-md5, weblogin, websessionuse. formerly: httpbasic.
17 // todo: we currently only use badcreds, but known baduser can be helpful
18 "result", // ok, baduser, badpassword, badcreds, error, aborted
19 },
20 )
21
22 metricAuthRatelimited = promauto.NewCounterVec(
23 prometheus.CounterOpts{
24 Name: "mox_authentication_ratelimited_total",
25 Help: "Authentication attempts that were refused due to rate limiting.",
26 },
27 []string{
28 "kind", // submission, imap, httpaccount, httpadmin
29 },
30 )
31)
32
33func AuthenticationInc(kind, variant, result string) {
34 metricAuth.WithLabelValues(kind, variant, result).Inc()
35}
36
37func AuthenticationRatelimitedInc(kind string) {
38 metricAuthRatelimited.WithLabelValues(kind).Inc()
39}
40