Udostępnianie metryk za pomocą Actuator i Prometheus
Udostępniaj stan bramy i metryki tras przez Spring Boot Actuator, a następnie zbieraj je za pomocą Prometheus, aby uzyskać pełną obserwowalność.
Udostępnianie metryk za pomocą Actuator i Prometheus to bezpłatna lekcja API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Udostępnianie metryk za pomocą Actuator i Prometheus” jest bezpłatna?
Tak — pełny tekst „Udostępnianie metryk za pomocą Actuator i Prometheus” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), przejdź na CoddyKit PRO. Kurs API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) zawiera 4 lekcji w sumie.
Co nauczysz się w „Udostępnianie metryk za pomocą Actuator i Prometheus”?
Udostępniaj stan bramy i metryki tras przez Spring Boot Actuator, a następnie zbieraj je za pomocą Prometheus, aby uzyskać pełną obserwowalność. Ćwiczysz API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
Nie wymagamy żadnego doświadczenia. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Udostępnianie metryk za pomocą Actuator i Prometheus”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
Tak. Każda lekcja API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Uwierzytelnianie i autoryzacja JWT
- Śledzenie rozproszone za pomocą Sleuth i Zipkin
- Scentralizowana konfiguracja za pomocą Config Server
- Udostępnianie metryk za pomocą Actuator i Prometheus