Track the number of expired emails form logs
This commit is contained in:
parent
8966f65067
commit
4470123df6
@ -53,6 +53,7 @@ type PostfixExporter struct {
|
|||||||
qmgrInsertsNrcpt prometheus.Histogram
|
qmgrInsertsNrcpt prometheus.Histogram
|
||||||
qmgrInsertsSize prometheus.Histogram
|
qmgrInsertsSize prometheus.Histogram
|
||||||
qmgrRemoves prometheus.Counter
|
qmgrRemoves prometheus.Counter
|
||||||
|
qmgrExpires prometheus.Counter
|
||||||
smtpDelays *prometheus.HistogramVec
|
smtpDelays *prometheus.HistogramVec
|
||||||
smtpTLSConnects *prometheus.CounterVec
|
smtpTLSConnects *prometheus.CounterVec
|
||||||
smtpConnectionTimedOut prometheus.Counter
|
smtpConnectionTimedOut prometheus.Counter
|
||||||
@ -294,6 +295,7 @@ var (
|
|||||||
logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`)
|
logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`)
|
||||||
lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `)
|
lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `)
|
||||||
qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `)
|
qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `)
|
||||||
|
qmgrExpiredLine = regexp.MustCompile(`:.*, status=(expired|force-expired), returned to sender`)
|
||||||
smtpStatusLine = regexp.MustCompile(`, status=(\w+) `)
|
smtpStatusLine = regexp.MustCompile(`, status=(\w+) `)
|
||||||
smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`)
|
smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`)
|
||||||
smtpConnectionTimedOut = regexp.MustCompile(`^connect\s+to\s+(.*)\[(.*)\]:(\d+):\s+(Connection timed out)$`)
|
smtpConnectionTimedOut = regexp.MustCompile(`^connect\s+to\s+(.*)\[(.*)\]:(\d+):\s+(Connection timed out)$`)
|
||||||
@ -356,6 +358,8 @@ func (e *PostfixExporter) CollectFromLogLine(line string) {
|
|||||||
addToHistogram(e.qmgrInsertsNrcpt, qmgrInsertMatches[2], "QMGR nrcpt")
|
addToHistogram(e.qmgrInsertsNrcpt, qmgrInsertMatches[2], "QMGR nrcpt")
|
||||||
} else if strings.HasSuffix(remainder, ": removed") {
|
} else if strings.HasSuffix(remainder, ": removed") {
|
||||||
e.qmgrRemoves.Inc()
|
e.qmgrRemoves.Inc()
|
||||||
|
} else if qmgrExpired := qmgrExpiredLine.FindStringSubmatch(remainder); qmgrExpired != nil {
|
||||||
|
e.qmgrExpires.Inc()
|
||||||
} else {
|
} else {
|
||||||
e.addToUnsupportedLine(line, subprocess)
|
e.addToUnsupportedLine(line, subprocess)
|
||||||
}
|
}
|
||||||
@ -505,6 +509,11 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines
|
|||||||
Name: "qmgr_messages_removed_total",
|
Name: "qmgr_messages_removed_total",
|
||||||
Help: "Total number of messages removed from mail queues.",
|
Help: "Total number of messages removed from mail queues.",
|
||||||
}),
|
}),
|
||||||
|
qmgrExpires: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "postfix",
|
||||||
|
Name: "qmgr_messages_expired_total",
|
||||||
|
Help: "Total number of messages expired from mail queues.",
|
||||||
|
}),
|
||||||
smtpDelays: prometheus.NewHistogramVec(
|
smtpDelays: prometheus.NewHistogramVec(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
Namespace: "postfix",
|
Namespace: "postfix",
|
||||||
@ -633,6 +642,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) {
|
|||||||
ch <- e.qmgrInsertsNrcpt.Desc()
|
ch <- e.qmgrInsertsNrcpt.Desc()
|
||||||
ch <- e.qmgrInsertsSize.Desc()
|
ch <- e.qmgrInsertsSize.Desc()
|
||||||
ch <- e.qmgrRemoves.Desc()
|
ch <- e.qmgrRemoves.Desc()
|
||||||
|
ch <- e.qmgrExpires.Desc()
|
||||||
e.smtpDelays.Describe(ch)
|
e.smtpDelays.Describe(ch)
|
||||||
e.smtpTLSConnects.Describe(ch)
|
e.smtpTLSConnects.Describe(ch)
|
||||||
ch <- e.smtpDeferreds.Desc()
|
ch <- e.smtpDeferreds.Desc()
|
||||||
@ -711,6 +721,7 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) {
|
|||||||
ch <- e.qmgrInsertsNrcpt
|
ch <- e.qmgrInsertsNrcpt
|
||||||
ch <- e.qmgrInsertsSize
|
ch <- e.qmgrInsertsSize
|
||||||
ch <- e.qmgrRemoves
|
ch <- e.qmgrRemoves
|
||||||
|
ch <- e.qmgrExpires
|
||||||
e.smtpDelays.Collect(ch)
|
e.smtpDelays.Collect(ch)
|
||||||
e.smtpTLSConnects.Collect(ch)
|
e.smtpTLSConnects.Collect(ch)
|
||||||
ch <- e.smtpDeferreds
|
ch <- e.smtpDeferreds
|
||||||
|
@ -20,6 +20,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) {
|
|||||||
qmgrInsertsNrcpt prometheus.Histogram
|
qmgrInsertsNrcpt prometheus.Histogram
|
||||||
qmgrInsertsSize prometheus.Histogram
|
qmgrInsertsSize prometheus.Histogram
|
||||||
qmgrRemoves prometheus.Counter
|
qmgrRemoves prometheus.Counter
|
||||||
|
qmgrExpires prometheus.Counter
|
||||||
smtpDelays *prometheus.HistogramVec
|
smtpDelays *prometheus.HistogramVec
|
||||||
smtpTLSConnects *prometheus.CounterVec
|
smtpTLSConnects *prometheus.CounterVec
|
||||||
smtpDeferreds prometheus.Counter
|
smtpDeferreds prometheus.Counter
|
||||||
@ -40,6 +41,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) {
|
|||||||
type args struct {
|
type args struct {
|
||||||
line []string
|
line []string
|
||||||
removedCount int
|
removedCount int
|
||||||
|
expiredCount int
|
||||||
saslFailedCount int
|
saslFailedCount int
|
||||||
outgoingTLS int
|
outgoingTLS int
|
||||||
smtpdMessagesProcessed int
|
smtpdMessagesProcessed int
|
||||||
@ -110,6 +112,19 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) {
|
|||||||
unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}),
|
unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "qmgr expired",
|
||||||
|
args: args{
|
||||||
|
line: []string{
|
||||||
|
"Apr 10 14:50:16 mail postfix/qmgr[3663]: BACE842E72: from=<noreply@domain.com>, status=expired, returned to sender",
|
||||||
|
"Apr 10 14:50:16 mail postfix/qmgr[3663]: BACE842E73: from=<noreply@domain.com>, status=force-expired, returned to sender",
|
||||||
|
},
|
||||||
|
expiredCount: 2,
|
||||||
|
},
|
||||||
|
fields: fields{
|
||||||
|
qmgrExpires: prometheus.NewCounter(prometheus.CounterOpts{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "SASL Failed",
|
name: "SASL Failed",
|
||||||
args: args{
|
args: args{
|
||||||
@ -225,6 +240,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) {
|
|||||||
qmgrInsertsNrcpt: tt.fields.qmgrInsertsNrcpt,
|
qmgrInsertsNrcpt: tt.fields.qmgrInsertsNrcpt,
|
||||||
qmgrInsertsSize: tt.fields.qmgrInsertsSize,
|
qmgrInsertsSize: tt.fields.qmgrInsertsSize,
|
||||||
qmgrRemoves: tt.fields.qmgrRemoves,
|
qmgrRemoves: tt.fields.qmgrRemoves,
|
||||||
|
qmgrExpires: tt.fields.qmgrExpires,
|
||||||
smtpDelays: tt.fields.smtpDelays,
|
smtpDelays: tt.fields.smtpDelays,
|
||||||
smtpTLSConnects: tt.fields.smtpTLSConnects,
|
smtpTLSConnects: tt.fields.smtpTLSConnects,
|
||||||
smtpDeferreds: tt.fields.smtpDeferreds,
|
smtpDeferreds: tt.fields.smtpDeferreds,
|
||||||
@ -247,6 +263,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) {
|
|||||||
e.CollectFromLogLine(line)
|
e.CollectFromLogLine(line)
|
||||||
}
|
}
|
||||||
assertCounterEquals(t, e.qmgrRemoves, tt.args.removedCount, "Wrong number of lines counted")
|
assertCounterEquals(t, e.qmgrRemoves, tt.args.removedCount, "Wrong number of lines counted")
|
||||||
|
assertCounterEquals(t, e.qmgrExpires, tt.args.expiredCount, "Wrong number of qmgr expired lines counted")
|
||||||
assertCounterEquals(t, e.smtpdSASLAuthenticationFailures, tt.args.saslFailedCount, "Wrong number of Sasl counter counted")
|
assertCounterEquals(t, e.smtpdSASLAuthenticationFailures, tt.args.saslFailedCount, "Wrong number of Sasl counter counted")
|
||||||
assertCounterEquals(t, e.smtpTLSConnects, tt.args.outgoingTLS, "Wrong number of TLS connections counted")
|
assertCounterEquals(t, e.smtpTLSConnects, tt.args.outgoingTLS, "Wrong number of TLS connections counted")
|
||||||
assertCounterEquals(t, e.smtpdProcesses, tt.args.smtpdMessagesProcessed, "Wrong number of smtpd messages processed")
|
assertCounterEquals(t, e.smtpdProcesses, tt.args.smtpdMessagesProcessed, "Wrong number of smtpd messages processed")
|
||||||
|
Loading…
Reference in New Issue
Block a user