From 727fd1195a4a54de764f2411c4b17c05c943b073 Mon Sep 17 00:00:00 2001 From: Maksim Totmin Date: Thu, 25 Jun 2026 23:27:12 +0700 Subject: [PATCH] feat: add route_fallbacks metric to Prometheus and Zabbix monitoring - Prometheus: new pulse_route_fallbacks_total counter - Zabbix: extend response with route_requests_total, route_fallbacks_total, uptime_seconds - Docs: update Prometheus metrics table and Zabbix response example --- docs/api.md | 6 +++++- internal/api/monitoring.go | 12 +++++++++++- internal/models/types.go | 5 ++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 350d65f..24f0b04 100644 --- a/docs/api.md +++ b/docs/api.md @@ -216,7 +216,10 @@ Use `X-API-Key` header (not JWT). "{#IS_STALE}": false, "{#SECONDS_AGO}": 3.0 } - ] + ], + "route_requests_total": 5000, + "route_fallbacks_total": 42, + "uptime_seconds": 7200 } ``` @@ -225,6 +228,7 @@ Use `X-API-Key` header (not JWT). | Метрика | Type | Labels | |---------|------|--------| | `pulse_route_requests_total` | counter | – | +| `pulse_route_fallbacks_total` | counter | – | | `pulse_nodes_total` | gauge | – | | `pulse_nodes_healthy` | gauge | – | | `pulse_uptime_seconds` | gauge | – | diff --git a/internal/api/monitoring.go b/internal/api/monitoring.go index b2aded8..1a0c63f 100644 --- a/internal/api/monitoring.go +++ b/internal/api/monitoring.go @@ -29,7 +29,13 @@ func (a *API) handleZabbix(w http.ResponseWriter, r *http.Request) { }) } - writeJSON(w, http.StatusOK, models.ZabbixResponse{Data: data}) + stats := a.engine.GetHealthStats() + writeJSON(w, http.StatusOK, models.ZabbixResponse{ + Data: data, + RouteRequests: stats.RouteRequests, + RouteFallbacks: stats.RouteFallbacks, + UptimeSeconds: stats.UptimeSeconds, + }) } // handlePrometheus — GET /api/monitoring/prometheus — text/plain метрики для Prometheus. @@ -52,6 +58,10 @@ func (a *API) handlePrometheus(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(&sb, "# TYPE pulse_nodes_healthy gauge\n") fmt.Fprintf(&sb, "pulse_nodes_healthy %d\n", stats.HealthyNodes) + fmt.Fprintf(&sb, "# HELP pulse_route_fallbacks_total Total number of fallback route requests.\n") + fmt.Fprintf(&sb, "# TYPE pulse_route_fallbacks_total counter\n") + fmt.Fprintf(&sb, "pulse_route_fallbacks_total %d\n", stats.RouteFallbacks) + fmt.Fprintf(&sb, "# HELP pulse_uptime_seconds Uptime in seconds.\n") fmt.Fprintf(&sb, "# TYPE pulse_uptime_seconds gauge\n") fmt.Fprintf(&sb, "pulse_uptime_seconds %d\n", stats.UptimeSeconds) diff --git a/internal/models/types.go b/internal/models/types.go index bc23853..4932689 100644 --- a/internal/models/types.go +++ b/internal/models/types.go @@ -241,7 +241,10 @@ type ZabbixNode struct { // ZabbixResponse — ответ на запрос Zabbix LLD. type ZabbixResponse struct { - Data []ZabbixNode `json:"data"` + Data []ZabbixNode `json:"data"` + RouteRequests int64 `json:"route_requests_total"` + RouteFallbacks int64 `json:"route_fallbacks_total"` + UptimeSeconds int64 `json:"uptime_seconds"` } // --- Balancer ---