DEV Community

Russ Miles for Reliably

Posted on • Updated on

Observing the Reliability of your Java Apps and Services with Spring Boot, Micrometer, Prometheus & Reliably

Photo by [Marten Newhall]( on [Unsplash](

Here at Reliably we are huge fans of Spring Boot and the Micrometer dimensional metrics instrumentation library for providing the rich set of possible metrics that can be a great foundation for the Service Level Indicators that provide coverage for your Reliably Service Level Objectives as Code.

As of Spring Boot 2.0, Micrometer became the default instrumentation library for the huge range of Spring Boot applications, from monoliths to microservices. With Micrometer bakes in by default, we started to explore just how easy it would be to bring Reliably's "Developer-First" SLOs to bear on your Spring Boot apps and services.

In this article we share our findings including how Reliably really can work "Bootifully" (TM, Josh Long :) ) with all your Spring Boot apps and services, out of the box and with no extra code required!

NOTE: The full coded sample for this article is available on GitHub.

The Setup: Spring Boot, Prometheus & Reliably

The exercise we wanted to conduct was to show how you could define and collaborate on Reliably Service Level Objectives that were measuring the availability of a simple Spring Boot service. To do this we needed three pieces in the mix:

With this approach, Spring Boot and Micrometer would push dimensional metrics to Prometheus. Then Reliably would use Prometheus queries to collate Service Level Indicators to back the Service Level Objectives being observed. Simple? Actually, it is…

NOTE: We chose Prometheus for this particular article but we could just have easily picked one of the other tools supported by Micrometer and Reliably, such as DataDog.

Sourcing Metrics from our Spring Boot Service

To get things built as quickly and easily as possible, we used the Spring Initializr to generate a very simple HTTP-based application that did nothing more than provide a default root / response of "Greetings from Spring Boot!" to provide the service that we'd look to observe our SLOs on.

As mentioned in the introduction, by default Spring Boot applications come with all the power of Micrometer by default, the only thing we needed to do was make sure that our Spring Boot service's metrics could be scraped by Prometheus by adding a single line to our service's

Setting up Prometheus to Scrape the Metrics

Next we added a simple Scraper configuration to our instance of Prometheus to periodically grab all the Micrometer metrics for our Spring Boot service from the endpoint we configured in the previous step:

With this config in place, Prometheus will grab the metrics from our Spring Boot service every 15 seconds.

Creating and Observing the Reliably SLOs as Code

The final step was for us to use the new Prometheus support in the Reliably CLI v0.23.0 to create our SLO with an SLI implemented as an appropriate Prometheus query:

This SLO definition includes a Service Level Indicator (SLI) that queries Prometheus for the appropriate metrics to help us judge that the SLO is being met, or not.

Pushing your SLIs to Reliably

With your Service Level Objective, and corresponding Prometheus-driven Service Level Indicators, in hand, you can now begin pushing the SLO and SLIs over time to Reliably using the reliably slo agent command:

$ reliably slo agent -i 10
INFO[0000] --- starting slo indicator agent ---         
INFO[0000] getting indicators for objective: [name='99% of requests return 2xx over last 1 hour', service='my spring boot app'] 
INFO[0000] indicator percent: [98.91] for objective: [name='99% of requests return 2xx over last 1 hour', service='my spring boot app'] 
Enter fullscreen mode Exit fullscreen mode

Observing your SLOs from your Command Line

With our Spring Boot service running and receiving requests, our Prometheus instance scraping the available metrics, and Reliably monitoring the above SLO, we have successfully defined and can observe a Java Spring Boot application's reliability with as little code as possible! The final step is to observe the status of your SLO using the reliably slo report -w -m reliably.yaml command:

Alt Text

Where to go next: We need … You!

Our goal is to shift reliability left by making it as easy as possible for you and your team to be able to define, observe and learn how to make your system's reliable. As such we are constantly looking to make it easier for people to collaborate, code and observe Service Level Objectives and Indicators for their own bespoke needs.

You can check out all the different tools that we currently integrate with in our docs, but if there's something you don't see then please get in touch or maybe even raise a ticket and PR yourself on our free and open source Reliably CLI project.

Top comments (0)