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:
parent
964fbfd0f8
commit
22a165da3e
1 changed files with 18 additions and 3 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue