From 22a165da3ee33473ebb1cbc3f071780b3ec7cd5b Mon Sep 17 00:00:00 2001 From: Hector Date: Tue, 21 Sep 2021 09:34:23 +0100 Subject: [PATCH] feat: improve startup logging Update the exporter startup to add more log messages. The server address, port, and metrics path are now logged on startup. A "ready" log message is printed when the server is up and running. --- src/exporter.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/exporter.go b/src/exporter.go index c30dcce..6cc8793 100644 --- a/src/exporter.go +++ b/src/exporter.go @@ -12,6 +12,10 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) +const ( + metricsPath = "/metrics" +) + var ( version = "dev" commit = "none" @@ -29,12 +33,23 @@ func main() { if appSettings.VersionMode { printAppVersion() } else { - log.Print("starting fail2ban exporter") + addr := fmt.Sprintf("0.0.0.0:%d", appSettings.MetricsPort) + + log.Printf("starting fail2ban exporter at %s", addr) exporter := export.NewExporter(appSettings, version) prometheus.MustRegister(exporter) - http.Handle("/metrics", promhttp.Handler()) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appSettings.MetricsPort), nil)) + http.Handle(metricsPath, promhttp.Handler()) + log.Printf("metrics available at '%s'", metricsPath) + + svrErr := make(chan error) + go func() { + svrErr <- http.ListenAndServe(addr, nil) + }() + log.Print("ready") + + err := <-svrErr + log.Print(err) } }