03f5084020
Split out all the code to define exporter functions and collect data into a new package. The new package is responsible for all exporter related activity. This makes the code easier to read. Split the code for collecting metrics from the database and from the socket into different files to make the separation more obvious.
40 lines
885 B
Go
40 lines
885 B
Go
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)
|
|
}
|
|
|
|
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))
|
|
}
|
|
}
|