1package metrics
2
3import (
4 "github.com/prometheus/client_golang/prometheus"
5 "github.com/prometheus/client_golang/prometheus/promauto"
6)
7
8var metricPanic = promauto.NewCounterVec(
9 prometheus.CounterOpts{
10 Name: "mox_panic_total",
11 Help: "Number of unhandled panics, by package.",
12 },
13 []string{
14 "pkg",
15 },
16)
17
18type Panic string
19
20const (
21 Ctl Panic = "ctl"
22 Import Panic = "import"
23 Serve Panic = "serve"
24 Imapserver Panic = "imapserver"
25 Dmarcdb Panic = "dmarcdb"
26 Mtastsdb Panic = "mtastsdb"
27 Queue Panic = "queue"
28 Smtpclient Panic = "smtpclient"
29 Smtpserver Panic = "smtpserver"
30 Tlsrptdb Panic = "tlsrptdb"
31 Dkimverify Panic = "dkimverify"
32 Spfverify Panic = "spfverify"
33 Upgradethreads Panic = "upgradethreads"
34 Importmanage Panic = "importmanage"
35 Importmessages Panic = "importmessages"
36 Store Panic = "store"
37 Webadmin Panic = "webadmin"
38 Webapi Panic = "webapi"
39 Webmailsendevent Panic = "webmailsendevent"
40 Webmail Panic = "webmail"
41 Webmailrequest Panic = "webmailrequest"
42 Webmailquery Panic = "webmailquery"
43 Webmailhandle Panic = "webmailhandle"
44)
45
46func init() {
47 // Ensure the panic counts are initialized to 0, so the query for change also picks
48 // up the first panic.
49 names := []Panic{
50 Ctl,
51 Import,
52 Serve,
53 Imapserver,
54 Mtastsdb,
55 Queue,
56 Smtpclient,
57 Smtpserver,
58 Dkimverify,
59 Spfverify,
60 Upgradethreads,
61 Importmanage,
62 Importmessages,
63 Webadmin,
64 Webmailsendevent,
65 Webmail,
66 Webmailrequest,
67 Webmailquery,
68 Webmailhandle,
69 }
70 for _, name := range names {
71 metricPanic.WithLabelValues(string(name)).Add(0)
72 }
73}
74
75func PanicInc(name Panic) {
76 metricPanic.WithLabelValues(string(name)).Inc()
77}
78