Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update regexp for support multi-instances logs #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions postfix_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ type PostfixExporter struct {
logUnsupportedLines bool

// Metrics that should persist after refreshes, based on logs.
cleanupProcesses prometheus.Counter
cleanupRejects prometheus.Counter
cleanupNotAccepted prometheus.Counter
lmtpDelays *prometheus.HistogramVec
pipeDelays *prometheus.HistogramVec
qmgrInsertsNrcpt prometheus.Histogram
qmgrInsertsSize prometheus.Histogram
qmgrRemoves prometheus.Counter
qmgrExpires prometheus.Counter
smtpDelays *prometheus.HistogramVec
smtpTLSConnects *prometheus.CounterVec
smtpConnectionTimedOut prometheus.Counter
smtpProcesses *prometheus.CounterVec
cleanupProcesses prometheus.Counter
cleanupRejects prometheus.Counter
cleanupNotAccepted prometheus.Counter
lmtpDelays *prometheus.HistogramVec
pipeDelays *prometheus.HistogramVec
qmgrInsertsNrcpt prometheus.Histogram
qmgrInsertsSize prometheus.Histogram
qmgrRemoves prometheus.Counter
qmgrExpires prometheus.Counter
smtpDelays *prometheus.HistogramVec
smtpTLSConnects *prometheus.CounterVec
smtpConnectionTimedOut prometheus.Counter
smtpProcesses *prometheus.CounterVec
// should be the same as smtpProcesses{status=deferred}, kept for compatibility, but this doesn't work !
smtpDeferreds prometheus.Counter
smtpdConnects prometheus.Counter
Expand All @@ -70,10 +70,10 @@ type PostfixExporter struct {
smtpdTLSConnects *prometheus.CounterVec
unsupportedLogEntries *prometheus.CounterVec
// same as smtpProcesses{status=deferred}, kept for compatibility
smtpStatusDeferred prometheus.Counter
opendkimSignatureAdded *prometheus.CounterVec
bounceNonDelivery prometheus.Counter
virtualDelivered prometheus.Counter
smtpStatusDeferred prometheus.Counter
opendkimSignatureAdded *prometheus.CounterVec
bounceNonDelivery prometheus.Counter
virtualDelivered prometheus.Counter
}

// A LogSource is an interface to read log lines.
Expand Down Expand Up @@ -292,7 +292,7 @@ func CollectShowqFromSocket(path string, ch chan<- prometheus.Metric) error {

// Patterns for parsing log messages.
var (
logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: ((?:(warning|error|fatal|panic): )?.*)`)
logLine = regexp.MustCompile(` ?(postfix[^\/]*|opendkim)(\/(\w+))?\[\d+\]: ((?:(warning|error|fatal|panic): )?.*)`)
lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `)
qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `)
qmgrExpiredLine = regexp.MustCompile(`:.*, status=(expired|force-expired), returned to sender`)
Expand Down Expand Up @@ -322,8 +322,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) {
process := logMatches[1]
level := logMatches[5]
remainder := logMatches[4]
switch process {
case "postfix":
if strings.Contains(process, "postfix") {
// Group patterns to check by Postfix service.
subprocess := logMatches[3]
switch subprocess {
Expand Down Expand Up @@ -420,13 +419,13 @@ func (e *PostfixExporter) CollectFromLogLine(line string) {
default:
e.addToUnsupportedLine(line, subprocess, level)
}
case "opendkim":
} else if process == "opendkim" {
if opendkimMatches := opendkimSignatureAdded.FindStringSubmatch(remainder); opendkimMatches != nil {
e.opendkimSignatureAdded.WithLabelValues(opendkimMatches[1], opendkimMatches[2]).Inc()
} else {
e.addToUnsupportedLine(line, process, level)
}
default:
} else {
// Unknown log entry format.
e.addToUnsupportedLine(line, process, level)
}
Expand Down