Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 85

    Monitoring Tools

    Metrics alone are not a monitoring stack.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Metrics alone are not a monitoring stack. For TechLearningPRO Orders on Spring Boot 3 / Java 21, the practical toolkit is Micrometer + Actuator emitting to Prometheus, visualized in Grafana, with logs in Loki (or a SaaS equivalent) and traces in Tempo / OpenTelemetry. SaaS stacks (Datadog, New Relic, Honeycomb) replace the same pillars with one agent.

    Choose tools by the four golden signals: latency, traffic, errors, and saturation. Orders needs endpoint histograms, RPS, 5xx rate, Hikari wait, JVM heap, and GC — not fifty vanity gauges.

    Self-hosted vs SaaS is a cost and ops trade-off; the Micrometer API stays the same. What changes is scrape vs push, retention, and who owns the pager.

    This lesson maps the tool landscape so later production lessons wire alerts on user-visible symptoms, not noisy infra noise.

    Purpose of this lesson

    Select and place Prometheus/Grafana (or SaaS) tools around Orders so golden-signal dashboards and alerts are ready before scaling work.

    Understanding the topic

    One observability pipeline, four golden signals, tool choice second.

    • Latency: p50/p95/p99 per Orders endpoint (Micrometer timers).
    • Traffic: RPS and top paths — Prometheus counters / rate().
    • Errors: 5xx and domain failure counters, not only HTTP status.
    • Saturation: CPU, heap, GC, DB pool, queue depth.
    • Stacks: Prometheus+Grafana+Loki+Tempo, or Datadog/New Relic/Honeycomb.

    Step-by-step explanation

    1. Confirm Actuator exposes prometheus (or your SaaS Micrometer registry).
    2. Scrape Orders with Prometheus or install the SaaS agent; tag application=orders.
    3. Build one Grafana (or SaaS) overview: latency, RPS, errors, Hikari active/pending.
    4. Add an alert on checkout p99 or 5xx burn — not on disk % of a healthy node.

    Informative example

    Prometheus scrape + a Grafana-ready business timer on Orders.

    yaml
    # prometheus.yml (excerpt)
    scrape_configs:
    - job_name: orders
    metrics_path: /actuator/prometheus
    static_configs:
    - targets: ["orders:8081"]
    labels:
    application: orders
    env: prod
    // OrderService — Micrometer timer (Boot 3)
    @Service
    public class OrderService {
    private final Timer placeTimer;
    private final OrderRepository orders;
    public OrderService(MeterRegistry registry, OrderRepository orders) {
    this.placeTimer = Timer.builder("orders.place")
    .publishPercentiles(0.5, 0.95, 0.99)
    .register(registry);
    this.orders = orders;
    }
    public OrderView place(CreateOrderRequest cmd) {
    return placeTimer.record(() -> OrderView.from(orders.save(OrderEntity.from(cmd))));
    }
    }

    Real-world use

    TechLearningPRO once had twelve Grafana panels of JVM trivia and no checkout latency chart. During a Black Friday spike, on-call could not see whether Orders or Inventory was slow. Replacing vanity dashboards with golden-signal panels plus a single orders.place timer cut MTTR from hours to minutes.

    Security implications

    Monitoring endpoints and agents are privileged surfaces.

    • Network-restrict or authenticate non-health Actuator endpoints.
    • Never ship real credentials in scrape configs — use placeholders like ${PROM_TOKEN}.
    • Redact PII from log-derived metrics and trace attributes.

    Best practices

    • Dashboards per service plus one executive overview page.
    • Alert on user-visible symptoms (latency, errors) with runbook links.
    • Keep Micrometer tags low-cardinality (tier, region, outcome).

    Common mistakes

    • Alerting on CPU alone while p99 checkout is already failing SLOs.
    • High-cardinality labels (raw orderId) exploding Prometheus series.
    • Leaving Actuator heapdump/env exposed on the public port.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionWhat are the four golden signals?+

    Answer

    Latency, traffic, errors, and saturation — enough to detect most user-visible incidents.
    2IntermediateQuestionWhy prefer Micrometer over a vendor-specific metrics API in Boot 3?+

    Answer

    One code path; swap Prometheus, Datadog, or others via registries without rewriting business metrics.
    3IntermediateQuestionWhen is SaaS better than self-hosted Prometheus?+

    Answer

    When you want managed retention, APM correlation, and less ops burden; cost and data residency become the trade-offs.

    Hands-on exercise

    Lab. Enable Micrometer Prometheus registry on Orders. Scrape /actuator/prometheus, graph orders_place percentiles in Grafana (or your SaaS UI), and write one alert rule for p99 above your SLO.

    Summary

    Monitoring tools turn Orders into an operable Boot 3 service. Next: use those signals to decide how and when to scale the backend.

    Ready to mark this lesson complete?Track your journey across the entire course.