This commit is contained in:
14
main.go
14
main.go
@@ -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))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user