34 lines
1.6 KiB
Go
34 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestClassifyQEMUAndLXCIO(t *testing.T) {
|
|
kind, name, vmid := classifyIOProcess(processIOSnapshot{name: "qemu", cmdline: "qemu-system-x86_64 -id 105 -name guest=test"}, map[int]string{105: "Gitea"})
|
|
if kind != "VM" || name != "Gitea" || vmid != 105 {
|
|
t.Fatalf("unexpected qemu attribution: %s %s %d", kind, name, vmid)
|
|
}
|
|
kind, name, vmid = classifyIOProcess(processIOSnapshot{name: "worker", cgroup: "0::/lxc.payload.220/ns"}, map[int]string{220: "db"})
|
|
if kind != "LXC" || name != "db" || vmid != 220 {
|
|
t.Fatalf("unexpected lxc attribution: %s %s %d", kind, name, vmid)
|
|
}
|
|
}
|
|
|
|
func TestActiveIOOperation(t *testing.T) {
|
|
value := activeIOOperation([]ProxmoxTask{{Type: "vzdump", ID: "105", Status: "", EndTime: 0}})
|
|
if !strings.Contains(value, "Backup") || !strings.Contains(value, "105") {
|
|
t.Fatalf("unexpected operation: %s", value)
|
|
}
|
|
}
|
|
|
|
func TestCorrelateAlerts(t *testing.T) {
|
|
metrics := dashboardMetrics{Disks: []DiskMetrics{{Name: "sda", IOCause: "Backup VM/LXC 105", IOConfidence: 90, Utilization: 98, LatencyMs: 80}}, Services: ServicesMetrics{Services: []ServiceStatus{{MonitoredService: MonitoredService{Name: "Gitea"}, Endpoints: []ServiceEndpointStatus{{Up: false}}}}}}
|
|
alerts := []Alert{{ID: "disk-io-pressure-sda", Severity: "critical"}, {ID: "service-1-public", Severity: "critical"}, {ID: "other", Severity: "warning"}}
|
|
result := correlateAlerts(metrics, alerts)
|
|
if len(result) != 2 || result[0].Source != "Корреляция" || !strings.Contains(result[0].Message, "Gitea") {
|
|
t.Fatalf("unexpected correlation: %+v", result)
|
|
}
|
|
}
|