You've already forked prometheus-fail2ban-exporter
remove: database-based metrics
Remove all database-based metrics from the metrics endpoint. Remove all code related to pulling metrics from the fail2ban database. Remove all configuration variables related to the fail2ban database. The CLI parameter for the database path was not removed to avoid breaking compatibility. Update docker entrypoint to remove references to the fail2ban database. Remove all references to the old database metrics from the README.
This commit is contained in:
@ -2,14 +2,12 @@ package f2b
|
||||
|
||||
import (
|
||||
"fail2ban-prometheus-exporter/cfg"
|
||||
fail2banDb "fail2ban-prometheus-exporter/db"
|
||||
"fail2ban-prometheus-exporter/socket"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Collector struct {
|
||||
db *fail2banDb.Fail2BanDB
|
||||
socketPath string
|
||||
exporterVersion string
|
||||
lastError error
|
||||
@ -19,65 +17,39 @@ type Collector struct {
|
||||
}
|
||||
|
||||
func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collector {
|
||||
colector := &Collector{
|
||||
return &Collector{
|
||||
socketPath: appSettings.Fail2BanSocketPath,
|
||||
exporterVersion: exporterVersion,
|
||||
lastError: nil,
|
||||
dbErrorCount: 0,
|
||||
socketConnectionErrorCount: 0,
|
||||
socketRequestErrorCount: 0,
|
||||
}
|
||||
if appSettings.Fail2BanDbPath != "" {
|
||||
log.Print("database-based metrics have been deprecated and will be removed in a future release")
|
||||
colector.db = fail2banDb.MustConnectToDb(appSettings.Fail2BanDbPath)
|
||||
}
|
||||
if appSettings.Fail2BanSocketPath != "" {
|
||||
colector.socketPath = appSettings.Fail2BanSocketPath
|
||||
}
|
||||
return colector
|
||||
}
|
||||
|
||||
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||
if c.db != nil {
|
||||
ch <- deprecatedMetricUp
|
||||
ch <- deprecatedMetricBadIpsPerJail
|
||||
ch <- deprecatedMetricBannedIpsPerJail
|
||||
ch <- deprecatedMetricEnabledJails
|
||||
ch <- deprecatedMetricErrorCount
|
||||
}
|
||||
if c.socketPath != "" {
|
||||
ch <- metricServerUp
|
||||
ch <- metricJailCount
|
||||
ch <- metricJailFailedCurrent
|
||||
ch <- metricJailFailedTotal
|
||||
ch <- metricJailBannedCurrent
|
||||
ch <- metricJailBannedTotal
|
||||
}
|
||||
ch <- metricServerUp
|
||||
ch <- metricJailCount
|
||||
ch <- metricJailFailedCurrent
|
||||
ch <- metricJailFailedTotal
|
||||
ch <- metricJailBannedCurrent
|
||||
ch <- metricJailBannedTotal
|
||||
ch <- metricErrorCount
|
||||
}
|
||||
|
||||
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
if c.db != nil {
|
||||
c.collectDeprecatedBadIpsPerJailMetrics(ch)
|
||||
c.collectDeprecatedBannedIpsPerJailMetrics(ch)
|
||||
c.collectDeprecatedEnabledJailMetrics(ch)
|
||||
c.collectDeprecatedUpMetric(ch)
|
||||
c.collectDeprecatedErrorCountMetric(ch)
|
||||
}
|
||||
if c.socketPath != "" {
|
||||
s, err := socket.ConnectToSocket(c.socketPath)
|
||||
if err != nil {
|
||||
log.Printf("error opening socket: %v", err)
|
||||
c.socketConnectionErrorCount++
|
||||
} else {
|
||||
defer s.Close()
|
||||
}
|
||||
c.collectServerUpMetric(ch, s)
|
||||
if err == nil && s != nil {
|
||||
c.collectJailMetrics(ch, s)
|
||||
}
|
||||
c.collectVersionMetric(ch, s)
|
||||
s, err := socket.ConnectToSocket(c.socketPath)
|
||||
if err != nil {
|
||||
log.Printf("error opening socket: %v", err)
|
||||
c.socketConnectionErrorCount++
|
||||
} else {
|
||||
c.collectVersionMetric(ch, nil)
|
||||
defer s.Close()
|
||||
}
|
||||
|
||||
c.collectServerUpMetric(ch, s)
|
||||
if err == nil && s != nil {
|
||||
c.collectJailMetrics(ch, s)
|
||||
c.collectVersionMetric(ch, s)
|
||||
}
|
||||
c.collectErrorCountMetric(ch)
|
||||
}
|
||||
|
Reference in New Issue
Block a user