Tuesday, September 30, 2025

Spring Boot Actuator, Prometheus, and Grafana

 Spring Boot Actuator, Prometheus, and Grafana usually work together as a monitoring stack::


🔹 1. Spring Boot Actuator

Purpose: Adds production-ready features to a Spring Boot app.
Uses:

  • Exposes health checks (e.g., /actuator/health) → check if the app is alive.

  • Provides metrics endpoints (e.g., /actuator/metrics) → JVM memory, CPU, HTTP request counts, datasource stats, etc.

  • Allows application monitoring & management → shutdown, environment info, logging levels (if enabled).

  • Acts as the data source for Prometheus when you add the micrometer-registry-prometheus dependency (exposes /actuator/prometheus).


🔹 2. Prometheus

Purpose: A time-series database & monitoring system.
Uses:

  • Scrapes metrics from targets (like /actuator/prometheus from your Spring Boot app).

  • Stores metrics as time series data.

  • Supports PromQL (Prometheus Query Language) to query and aggregate data.

  • Provides alerting (integrates with Alertmanager to send alerts via email, Slack, etc.).

  • Efficient for real-time monitoring of microservices, infrastructure, and applications.

Example: Prometheus pulls http_server_requests_seconds_count from Actuator and stores it with timestamps → lets you know how many requests hit your app.


🔹 3. Grafana

Purpose: A visualization and analytics tool.
Uses:

  • Connects to Prometheus (or other data sources) and builds dashboards.

  • Lets you plot charts, graphs, heatmaps for metrics.

  • Helps in root-cause analysis by correlating metrics (e.g., “CPU high → request latency increases”).

  • Can set up alerts with custom thresholds and send notifications (email, Teams, Slack, etc.).

  • Used to present monitoring data in a clear, user-friendly way for devs, ops, and managers.


🔗 How They Work Together

  1. Spring Boot Actuator → exposes metrics in a format Prometheus can read.

  2. Prometheus → scrapes those metrics at intervals (e.g., every 15s), stores them, and lets you query them.

  3. Grafana → queries Prometheus and builds interactive dashboards to visualize application health & performance.


In short:

  • Actuator = generates app metrics.

  • Prometheus = collects, stores, and queries metrics.

  • Grafana = visualizes and alerts on metrics.


No comments:

Post a Comment

🧠 How to Upgrade Your Spring Boot Login for Full OWASP Protection (XSS, CSRF, HttpOnly JWT)

 Modern web apps often use localStorage for JWTs — but that’s risky. localStorage is accessible to JavaScript , so an XSS attack can easi...