feat(go): track gateway active connections

This commit is contained in:
lingniu
2026-07-02 19:16:25 +08:00
parent 266a74f225
commit 41ff0bcef4
5 changed files with 143 additions and 20 deletions

View File

@@ -27,6 +27,25 @@ func TestRegistryRendersCountersWithLabels(t *testing.T) {
}
}
func TestRegistryRendersGaugesWithLabels(t *testing.T) {
registry := NewRegistry()
registry.SetGauge("vehicle_gateway_connections", Labels{"protocol": "JT808"}, 2)
registry.AddGauge("vehicle_gateway_connections", Labels{"protocol": "JT808"}, -1)
registry.SetGauge("vehicle_gateway_connections", Labels{"protocol": "GB32960"}, 3)
text := registry.Render()
for _, want := range []string{
`# TYPE vehicle_gateway_connections gauge`,
`vehicle_gateway_connections{protocol="GB32960"} 3`,
`vehicle_gateway_connections{protocol="JT808"} 1`,
} {
if !strings.Contains(text, want) {
t.Fatalf("metrics missing %s:\n%s", want, text)
}
}
}
func TestHandlerServesPrometheusText(t *testing.T) {
registry := NewRegistry()
registry.IncCounter("vehicle_kafka_commits_total", Labels{"service": "history"})