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.
This commit is contained in:
Hector 2021-09-21 09:34:23 +01:00
parent 964fbfd0f8
commit 22a165da3e

View file

@ -12,6 +12,10 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
const (
metricsPath = "/metrics"
)
var ( var (
version = "dev" version = "dev"
commit = "none" commit = "none"
@ -29,12 +33,23 @@ func main() {
if appSettings.VersionMode { if appSettings.VersionMode {
printAppVersion() printAppVersion()
} else { } 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) exporter := export.NewExporter(appSettings, version)
prometheus.MustRegister(exporter) prometheus.MustRegister(exporter)
http.Handle("/metrics", promhttp.Handler()) http.Handle(metricsPath, promhttp.Handler())
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appSettings.MetricsPort), nil)) 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)
} }
} }