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

Exposing Metrics with Actuator & Prometheus

Surface gateway health and route metrics through Spring Boot Actuator and scrape them with Prometheus for full observability.

Exposing Metrics with Actuator & Prometheus is a free API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

Is the “Exposing Metrics with Actuator & Prometheus” lesson free?

Yes — the full text of “Exposing Metrics with Actuator & Prometheus” is free to read here on the web, and the API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) course, upgrade to CoddyKit PRO.

What will I learn in “Exposing Metrics with Actuator & Prometheus”?

Surface gateway health and route metrics through Spring Boot Actuator and scrape them with Prometheus for full observability. You practise API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

No prior experience is required. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Exposing Metrics with Actuator & Prometheus” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) lesson?

Yes. Every API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. JWT Authentication & Authorization
  2. Distributed Tracing with Sleuth/Zipkin
  3. Centralized Configuration with Config Server
  4. Exposing Metrics with Actuator & Prometheus
← Back to API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)