From a85bda5e49e24d141f8e4d3898aee9060b20bd88 Mon Sep 17 00:00:00 2001 From: cw-ozaki Date: Wed, 22 Apr 2020 09:30:09 +0900 Subject: [PATCH] fixes panic appears when tailer is nil --- postfix_exporter.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 2e2ec22..9a53c63 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -612,6 +612,9 @@ func NewPostfixExporter(showqPath string, logfilePath string, journal *Journal, func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { ch <- postfixUpDesc + if e.tailer == nil { + return + } ch <- e.cleanupProcesses.Desc() ch <- e.cleanupRejects.Desc() ch <- e.cleanupNotAccepted.Desc() @@ -664,7 +667,7 @@ func (e *PostfixExporter) foreverCollectFromJournal(ctx context.Context) { func (e *PostfixExporter) StartMetricCollection(ctx context.Context) { if e.journal != nil { e.foreverCollectFromJournal(ctx) - } else { + } else if e.tailer != nil { e.CollectLogfileFromFile(ctx) } @@ -697,6 +700,9 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.showqPath) } + if e.tailer == nil { + return + } ch <- e.cleanupProcesses ch <- e.cleanupRejects ch <- e.cleanupNotAccepted