Skip to content

Commit

Permalink
Fix: "stray" foo
Browse files Browse the repository at this point in the history
- implement a sync map to keep tracking of overall listing per rbl/dnsbl
- removes the "foo" and instead adds luzilla_rbls_listed{rbl="..."} gauges

For: #107
  • Loading branch information
till committed May 14, 2022
1 parent 3d97c4b commit 3d88c55
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package collector

import (
"sync"

"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -73,8 +75,8 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {
float64(len(c.rbls)),
)

// this should be a map of blacklist and a counter
listed := 0
// this should be a map of blacklist and a counter (for listings)
var listed sync.Map

// iterate over hosts -> resolve to ip, check
for _, host := range hosts {
Expand All @@ -92,9 +94,10 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {

metricValue := 0

val, _ := listed.LoadOrStore(result.Rbl, 0)
if result.Listed {
metricValue = 1
listed = +1
listed.Store(result.Rbl, val.(int)+1)
}

labelValues := []string{result.Rbl, result.Address, host}
Expand All @@ -117,10 +120,14 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {
}
}

ch <- prometheus.MustNewConstMetric(
c.listedMetric,
prometheus.GaugeValue,
float64(listed),
[]string{"foo"}...,
)
for _, rbl := range c.rbls {
val, _ := listed.LoadOrStore(rbl, 0)
ch <- prometheus.MustNewConstMetric(
c.listedMetric,
prometheus.GaugeValue,
float64(val.(int)),
[]string{rbl}...,
)
}

}

0 comments on commit 3d88c55

Please sign in to comment.