This commit is contained in:
30
main.go
30
main.go
@@ -77,10 +77,17 @@ var (
|
|||||||
Name: "ipcheck_whitelisted_total",
|
Name: "ipcheck_whitelisted_total",
|
||||||
Help: "Total whitelisted IPs",
|
Help: "Total whitelisted IPs",
|
||||||
})
|
})
|
||||||
|
blocklistHashSizes = prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "ipcheck_blocklist_hash_size",
|
||||||
|
Help: "Number of entries in each category",
|
||||||
|
},
|
||||||
|
[]string{"category"},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(checkRequests, checkBlocked, checkWhitelist)
|
prometheus.MustRegister(checkRequests, checkBlocked, checkWhitelist, blocklistHashSizes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
@@ -98,10 +105,31 @@ func main() {
|
|||||||
http.HandleFunc("/traefik", handleTraefik)
|
http.HandleFunc("/traefik", handleTraefik)
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
updateBlocklistMetrics()
|
||||||
|
<-ticker.C
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
fmt.Println("Server läuft auf :8080")
|
fmt.Println("Server läuft auf :8080")
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateBlocklistMetrics() {
|
||||||
|
for cat := range blocklistURLs {
|
||||||
|
key := "bl:" + cat
|
||||||
|
count, err := rdb.HLen(ctx, key).Result()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("❌ Redis HLen Error for %s: %v\n", key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
blocklistHashSizes.WithLabelValues(cat).Set(float64(count))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Import-Logik
|
// Import-Logik
|
||||||
func importBlocklists() error {
|
func importBlocklists() error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
Reference in New Issue
Block a user