Updated Metrics
All checks were successful
release-tag / release-image (push) Successful in 1m42s

This commit is contained in:
2025-06-16 11:28:34 +02:00
parent 042bbc1c27
commit 5128e0641f
2 changed files with 31 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
# flod # flod
First-Line-Of-Defense First-Line-Of-Defense

30
main.go
View File

@@ -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