diff --git a/src/exporter.go b/src/exporter.go index 5ca325f..294e75a 100644 --- a/src/exporter.go +++ b/src/exporter.go @@ -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,17 @@ func (e *Exporter) collectJailStatsMetric(ch chan<- prometheus.Metric, s *socket ) } +func (e *Exporter) collectVersionMetric(ch chan<- prometheus.Metric, s *socket.Fail2BanSocket) { + fail2banVersion := "9.9.9" + if s != nil { + // TODO: Get fail2ban server version + } + + 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)