You've already forked prometheus-fail2ban-exporter
feat: export new version metric (#12)
Add a new `f2b_version` metric that includes the version of the fail2ban server and the exporter. Add a new socket command to get back the fail2ban server version.
This commit is contained in:
@ -85,6 +85,11 @@ var (
|
||||
"Total number of IPs banned by this jail (includes expired bans)",
|
||||
[]string{"jail"}, nil,
|
||||
)
|
||||
metricVersionInfo = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "version"),
|
||||
"Version of the exporter and fail2ban server",
|
||||
[]string{"exporter", "fail2ban"}, nil,
|
||||
)
|
||||
)
|
||||
|
||||
type Exporter struct {
|
||||
@ -135,6 +140,9 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
if err == nil && s != nil {
|
||||
e.collectJailMetrics(ch, s)
|
||||
}
|
||||
e.collectVersionMetric(ch, s)
|
||||
} else {
|
||||
e.collectVersionMetric(ch, nil)
|
||||
}
|
||||
e.collectErrorCountMetric(ch)
|
||||
}
|
||||
@ -273,6 +281,22 @@ func (e *Exporter) collectJailStatsMetric(ch chan<- prometheus.Metric, s *socket
|
||||
)
|
||||
}
|
||||
|
||||
func (e *Exporter) collectVersionMetric(ch chan<- prometheus.Metric, s *socket.Fail2BanSocket) {
|
||||
var err error
|
||||
var fail2banVersion = ""
|
||||
if s != nil {
|
||||
fail2banVersion, err = s.GetServerVersion()
|
||||
if err != nil {
|
||||
e.socketRequestErrorCount++
|
||||
log.Printf("failed to get fail2ban server version: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
metricVersionInfo, prometheus.GaugeValue, float64(1), version, fail2banVersion,
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user