prometheus-fail2ban-exporter/src/exporter.go

41 lines
885 B
Go
Raw Normal View History

2021-02-05 22:49:47 +00:00
package main
import (
"fail2ban-prometheus-exporter/cfg"
"fail2ban-prometheus-exporter/export"
"fmt"
"log"
"net/http"
_ "github.com/mattn/go-sqlite3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
func printAppVersion() {
fmt.Println(version)
fmt.Printf(" build date: %s\r\n commit hash: %s\r\n built by: %s\r\n", date, commit, builtBy)
}
2021-02-05 22:49:47 +00:00
func main() {
appSettings := cfg.Parse()
if appSettings.VersionMode {
printAppVersion()
} else {
log.Print("starting fail2ban exporter")
exporter := export.NewExporter(appSettings, version)
prometheus.MustRegister(exporter)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appSettings.MetricsPort), nil))
}
2021-02-05 22:49:47 +00:00
}