fix metrics
All checks were successful
release-tag / release-image (push) Successful in 1m38s

This commit is contained in:
2025-06-23 18:41:31 +02:00
parent d0d6154bec
commit 7aa77d9560

14
main.go
View File

@@ -192,15 +192,23 @@ func handleMetrics(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain") w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(fmt.Sprintf("honeypod_blocked_ips_total %d\n", totalIPs))) w.Write([]byte(fmt.Sprintf("honeypod_blocked_ips_total %d\n", totalIPs)))
// Map zum Zählen
portHitCounter := make(map[string]int)
for _, ip := range keys { for _, ip := range keys {
ports, _ := redisClient.SMembers(ctx, "bl:manual:"+ip).Result() ports, _ := redisClient.SMembers(ctx, "bl:manual:"+ip).Result()
for _, p := range ports { for _, p := range ports {
portHitCounter[p]++
}
}
// Jetzt pro Port+Proto Metriken ausgeben
for p, count := range portHitCounter {
parts := strings.Split(p, "/") parts := strings.Split(p, "/")
if len(parts) == 2 { if len(parts) == 2 {
port, proto := parts[0], parts[1] port, proto := parts[0], parts[1]
metricName := fmt.Sprintf("honeypod_port_hits{port=\"%s\",protocol=\"%s\"}", port, proto) metricName := fmt.Sprintf("honeypod_port_hits{port=\"%s\",protocol=\"%s\"} %d\n", port, proto, count)
w.Write([]byte(metricName + " 1\n")) // hier 1 pro IP/Port-Protokoll w.Write([]byte(metricName))
}
} }
} }
} }