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