Exposición de métricas con Actuator y Prometheus
Exponga la salud de la puerta de enlace y las métricas de las rutas mediante Spring Boot Actuator y recopílelas con Prometheus para obtener una observabilidad completa.
Exposición de métricas con Actuator y Prometheus es una lección gratuita de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Seeing Inside the Gateway
Tracing shows individual request journeys, but you also need aggregate metrics: request rates, error counts, latency. Spring Boot Actuator plus Micrometer expose these for the gateway.
Adding Actuator
The Actuator starter adds production-ready endpoints for health, info, and metrics.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Exposing Endpoints
By default most endpoints are hidden over HTTP. Expose the ones you need explicitly.
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus,gatewayThe Gateway Endpoint
The gateway actuator endpoint lists all active routes and their configuration, invaluable for debugging routing in a running system.
curl http://localhost:8080/actuator/gateway/routesMicrometer Metrics
Micrometer is the metrics facade. The gateway records timers like spring.cloud.gateway.requests tagged by route id, status, and method.
Enabling Gateway Metrics
Make sure metric collection for the gateway is turned on so per-route timers are recorded.
spring:
cloud:
gateway:
metrics:
enabled: trueThe Prometheus Registry
Add the Prometheus registry so metrics are published in Prometheus' text format at /actuator/prometheus.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>Inspecting the Scrape Endpoint
Hit the endpoint to see raw metrics. Prometheus will scrape this same URL on a schedule.
curl http://localhost:8080/actuator/prometheusConfiguring a Scrape Job
Point Prometheus at the gateway with a scrape job describing the path and target.
scrape_configs:
- job_name: gateway
metrics_path: /actuator/prometheus
static_configs:
- targets: ['gateway:8080']Useful Metrics to Watch
Key signals include request count, error rate (5xx), and p95 latency per route. Alert when error rate or latency crosses a threshold.
spring_cloud_gateway_requests_seconds_countspring_cloud_gateway_requests_seconds_max
Securing the Endpoints
Actuator endpoints can leak internals. In production restrict them to an internal network or protect them with authentication.
management:
endpoints:
web:
base-path: /internal/actuatorQuick Check
Which actuator endpoint exposes metrics in a format Prometheus can scrape?
Recap
You made the gateway observable:
- Actuator exposes health, metrics, and the gateway route view
- Micrometer records per-route timers
- The Prometheus registry serves
/actuator/prometheus - Prometheus scrapes and you alert on errors and latency
With tracing plus metrics you have end-to-end visibility into gateway traffic.
Preguntas frecuentes
¿La lección «Exposición de métricas con Actuator y Prometheus» es gratis?
Sí — el texto completo de «Exposición de métricas con Actuator y Prometheus» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), actualiza a CoddyKit PRO. El curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye 4 lecciones en total.
¿Qué aprenderé en «Exposición de métricas con Actuator y Prometheus»?
Exponga la salud de la puerta de enlace y las métricas de las rutas mediante Spring Boot Actuator y recopílelas con Prometheus para obtener una observabilidad completa. Practicas API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
No se requiere experiencia previa. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Exposición de métricas con Actuator y Prometheus»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
Sí. Cada lección de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Autenticación y autorización con JWT
- Trazabilidad distribuida con Sleuth/Zipkin
- Configuración centralizada con Config Server
- Exposición de métricas con Actuator y Prometheus