diff --git a/main.go b/main.go index 092c844..176d30d 100644 --- a/main.go +++ b/main.go @@ -192,15 +192,23 @@ func handleMetrics(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") 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 { ports, _ := redisClient.SMembers(ctx, "bl:manual:"+ip).Result() for _, p := range ports { - parts := strings.Split(p, "/") - if len(parts) == 2 { - port, proto := parts[0], parts[1] - metricName := fmt.Sprintf("honeypod_port_hits{port=\"%s\",protocol=\"%s\"}", port, proto) - w.Write([]byte(metricName + " 1\n")) // hier 1 pro IP/Port-Protokoll - } + portHitCounter[p]++ + } + } + + // Jetzt pro Port+Proto Metriken ausgeben + for p, count := range portHitCounter { + parts := strings.Split(p, "/") + if len(parts) == 2 { + port, proto := parts[0], parts[1] + metricName := fmt.Sprintf("honeypod_port_hits{port=\"%s\",protocol=\"%s\"} %d\n", port, proto, count) + w.Write([]byte(metricName)) } } }