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 Webmailsendevent Panic = "webmailsendevent"
39 Webmail Panic = "webmail"
40 Webmailrequest Panic = "webmailrequest"
41 Webmailquery Panic = "webmailquery"
42 Webmailhandle Panic = "webmailhandle"
43)
44
45func init() {
46 // Ensure the panic counts are initialized to 0, so the query for change also picks
47 // up the first panic.
48 names := []Panic{
49 Ctl,
50 Import,
51 Serve,
52 Imapserver,
53 Mtastsdb,
54 Queue,
55 Smtpclient,
56 Smtpserver,
57 Dkimverify,
58 Spfverify,
59 Upgradethreads,
60 Importmanage,
61 Importmessages,
62 Webadmin,
63 Webmailsendevent,
64 Webmail,
65 Webmailrequest,
66 Webmailquery,
67 Webmailhandle,
68 }
69 for _, name := range names {
70 metricPanic.WithLabelValues(string(name)).Add(0)
71 }
72}
73
74func PanicInc(name Panic) {
75 metricPanic.WithLabelValues(string(name)).Inc()
76}
77