refactor: create new collector folder
Create a new `collector` folder to store the code for the different collectors. Move the existing f2b and textfile collectors to this folder. Minor refactors to the f2b collector to better match the code style of the newer textfile collector.
This commit is contained in:
1 parent
7cdaf1ebd1
commit
60e6365e1f
9 files changed
+121
-127
No files matched your search
+6
-6
@@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fail2ban-prometheus-exporter/cfg"
|
||||
"fail2ban-prometheus-exporter/export"
|
||||
"fail2ban-prometheus-exporter/textfile"
|
||||
"fail2ban-prometheus-exporter/collector/f2b"
|
||||
textfile2 "fail2ban-prometheus-exporter/collector/textfile"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -44,7 +44,7 @@ func rootHtmlHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func metricHandler(w http.ResponseWriter, r *http.Request, collector *textfile.Collector) {
|
||||
func metricHandler(w http.ResponseWriter, r *http.Request, collector *textfile2.Collector) {
|
||||
promhttp.Handler().ServeHTTP(w, r)
|
||||
collector.WriteTextFileMetrics(w, r)
|
||||
}
|
||||
@@ -58,10 +58,10 @@ func main() {
|
||||
|
||||
log.Printf("starting fail2ban exporter at %s", addr)
|
||||
|
||||
exporter := export.NewExporter(appSettings, version)
|
||||
prometheus.MustRegister(exporter)
|
||||
f2bCollector := f2b.NewExporter(appSettings, version)
|
||||
prometheus.MustRegister(f2bCollector)
|
||||
|
||||
textFileCollector := textfile.NewCollector(appSettings)
|
||||
textFileCollector := textfile2.NewCollector(appSettings)
|
||||
prometheus.MustRegister(textFileCollector)
|
||||
|
||||
http.HandleFunc("/", rootHtmlHandler)
|
||||
|
||||
Reference in new issue
Block a user