You've already forked prometheus-fail2ban-exporter
feat: new metric for enabled jails (#1)
Add a new prometheus metric to track which jails are currently enabled. Add a new database query to read the jail name and enabled status from the database. Add new metric to readme file.
This commit is contained in:
@ -34,6 +34,11 @@ var (
|
||||
"Number of bad IPs stored in the database (per jail).",
|
||||
[]string{"jail"}, nil,
|
||||
)
|
||||
metricEnabledJails = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "enabled_jails"),
|
||||
"Enabled jails.",
|
||||
[]string{"jail"}, nil,
|
||||
)
|
||||
)
|
||||
|
||||
type Exporter struct {
|
||||
@ -44,6 +49,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- metricUp
|
||||
ch <- metricBadIpsPerJail
|
||||
ch <- metricBannedIpsPerJail
|
||||
ch <- metricEnabledJails
|
||||
}
|
||||
|
||||
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
@ -52,6 +58,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
)
|
||||
e.collectBadIpsPerJailMetrics(ch)
|
||||
e.collectBannedIpsPerJailMetrics(ch)
|
||||
e.collectEnabledJailMetrics(ch)
|
||||
}
|
||||
|
||||
func (e *Exporter) collectBadIpsPerJailMetrics(ch chan<- prometheus.Metric) {
|
||||
@ -80,6 +87,19 @@ func (e *Exporter) collectBannedIpsPerJailMetrics(ch chan<- prometheus.Metric) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Exporter) collectEnabledJailMetrics(ch chan<- prometheus.Metric) {
|
||||
jailNameToEnabledMap, err := e.db.JailNameToEnabledValue()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
for jailName, count := range jailNameToEnabledMap {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
metricEnabledJails, prometheus.GaugeValue, float64(count), jailName,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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