/SpringBootPrometheus

Monitor Spring Boot application

Primary LanguageJavaApache License 2.0Apache-2.0

Refer the readme.docs file attached for detailed instruction

Run the application : mvn spring-boot:run

Run supporting services : docker-compose up


image

image

  1. Spring Boot Actuator module includes a number of built-in endpoints that exposes app metrics.

  2. Spring Boot Actuator provides dependency management and auto-configuration for Micrometer.

image

  1. Micrometer, an application metrics facade that supports numerous monitoring systems, including: prometheus

  2. we are going to leverage HTTP endpoints to see metrics.

  3. Micrometer job is to expose our application metrics to external monitoring systems while prometheus job is to scape and store metrics information exposed by it.

image

  1. If multiple applications publish metrics data, Spring Boot can use a tag to identify the application name. It does it by registering MeterRegistry.

image

  1. The micrometer framework provides several types of the custom metrics or meters such as Counter, Gauge, Timer, DistributionSummary that you can use to create custom metrics

image

• Count the number of courses created using the Counter metric • Count the number of courses created using the Gauge metric. • Capture the time taken to create the course using the Timer metric • Capture the distribution summary of the course ratings using the DistributionSummary metric

Prometheus is a monitoring system and time-series database that allows us to store time-series data, which includes the metrics of an application over time, a simple way to visualize the metrics, or setting up alerts on different metrics.

We will now configure Prometheus to scrape Spring Boot metrics. To do that, open the prometheus.yml file and add the following job_name in the scrape_configs section:

image

Following Prometheus URL to see all registered endpoints: http://localhost:9090/targets

image

Capturing Spring Boot Metrics We can collection various metrics exposed by Spring Boot application: image

Within the Path “actuator/prometheus” there are many interesting metrics

image

image

image

WE can use PQL to narrow our specific metric data: image

image

image

Grafana allows you to obtain data from various data sources such as Prometheus and visualize it through exquisite graphics

image

Prometheus Push Gateway : The Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus. Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway. The Pushgateway then exposes these metrics to Prometheus.

image

image

image

prometheus-simpleclient_log4j2 : It’s a Metrics collector for log4j2 appender logging.

To register the Logback collector can be added to the root level in log4j2-spring.xml file.

image

image

image

Alertmanager manages alerts sent by Prometheus server. It takes care of grouping alerts, and routing them to the correct receiver. For example an email receiver, pager, webhook, sms etc.

Alerts are generally included in a separate file, in our case it’s rules.yml

image

RabbitMQ metric exporter to Prometheus:

While RabbitMQ management UI also provides access to a subset of metrics, it by design doesn't try to be a long term metric collection solution.

As of 3.8.0, RabbitMQ ships with built-in Prometheus & Grafana support.

With the rabbitmq_prometheus plugin, rabbitMq can ship metrics to default URL URL15692/metrics

image

Using the Alert Manager to signal Spring Boot metrics You can reach Prometheus Alert UI from Prometheus dashboard and see the configured alert

image

In case our Spring boot application is down alert agent triggers the alert to appropriate route.

image

Routing Alerts via email Finally, we can configure the Alert Manager to send mails whenever an alert reaches the firing state. To do that, we need to add the below configuration in alertmanager.yml

image image

Another important component is the Alert Manager: that shows the list of alerts that were fired,

image

Spring Boot’s Prometheus Metrics: http://localhost:8080/actuator/prometheus

Prometheus Target Endpoints: http://localhost:9090/targets

Prometheus Alerts: http://localhost:9090/alerts

Grafana server: http://localhost:3000

Alert Manager: http://localhost:9093

Pushgateway: http://localhost:9091

Rabbit-mq retric --> http://localhost:15692/metrics

GitHub Repo: https://github.com/royalespn/SpringBootPrometheus

GitHub: SpringBoot Scheduler: https://github.com/royalespn/SpringBootTaskScheduler

Run the application : mvn spring-boot:run

Run services : docker-compose up

Reference: Prometheus: Up & Running by Brian Brazil by by Brian Brazil, ISBN: 9781492034148

Spring Boot Actuautor: https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics