0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · Lezione

Esposizione delle metriche con Actuator e Prometheus

Renda disponibili lo stato di salute del gateway e le metriche delle route tramite Spring Boot Actuator e raccolga i dati con Prometheus per una completa osservabilità.

Esposizione delle metriche con Actuator e Prometheus è una lezione API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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,gateway

The 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/routes

Micrometer 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: true

The 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/prometheus

Configuring 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_count
  • spring_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/actuator

Quick 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.

Domande Frequenti

La lezione «Esposizione delle metriche con Actuator e Prometheus» è gratuita?

Sì — il testo completo di «Esposizione delle metriche con Actuator e Prometheus» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), passa a CoddyKit PRO. Il corso API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) include 4 lezioni in totale.

Cosa imparerò in «Esposizione delle metriche con Actuator e Prometheus»?

Renda disponibili lo stato di salute del gateway e le metriche delle route tramite Spring Boot Actuator e raccolga i dati con Prometheus per una completa osservabilità. Eserciti API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Non è richiesta alcuna esperienza precedente. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Esposizione delle metriche con Actuator e Prometheus»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Sì. Ogni lezione API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Autenticazione e autorizzazione con JWT
  2. Tracing distribuito con Sleuth/Zipkin
  3. Configurazione centralizzata con Config Server
  4. Esposizione delle metriche con Actuator e Prometheus
← Torna a API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)