prometheus-fail2ban-exporter/server/handler.go
Markus Pesch 3998f9e2c2
All checks were successful
continuous-integration/drone/push Build is passing
Initial Commit
2023-10-02 12:50:34 +02:00

34 lines
783 B
Go

package server
import (
"log"
"net/http"
"git.cryptic.systems/volker.raschek/prometheus-fail2ban-exporter/collector/textfile"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const (
metricsPath = "/metrics"
)
func rootHtmlHandler(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(
`<html>
<head><title>Fail2Ban Exporter</title></head>
<body>
<h1>Fail2Ban Exporter</h1>
<p><a href="` + metricsPath + `">Metrics</a></p>
</body>
</html>`))
if err != nil {
log.Printf("error handling root url: %v", err)
w.WriteHeader(http.StatusInternalServerError)
}
}
func metricHandler(w http.ResponseWriter, r *http.Request, collector *textfile.Collector) {
promhttp.Handler().ServeHTTP(w, r)
collector.WriteTextFileMetrics(w, r)
}