Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 6660

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 27, 20242024-11-27T08:35:08+00:00 2024-11-27T08:35:08+00:00

Spring boot metrics on Prometheus

  • 60k

Introduction

gif showing happy kid after discovering his code is working
After days of hard development, my application has been finally deployed to production! No user has reported bugs, so it seems everything is fine. But does it really?

I don't like to just deploy and move to the next task, so I feel the need for checking if my new API is healthy and breathing. So, I instantly open a new browser tab and go check the logs on Kibana.

Now I have to remember which relevant log messages I left behind, and also the Lucene syntax, but this isn't scalable since I can't do this for every deployment. This process also doesn't work for non-technical people, like the product manager. I really wish there was a dashboard where I could simply configure once and then just visualize all the metrics.

Prerequisites

download.png

The Spring boot API will expose data that will be collected by Prometheus and then displayed on Grafana. Java 8 will be required to run the Spring boot application.

If you want to know how to install Prometheus and Grafana on a Linux based OS, check my previous article.

Setup Spring

Screenshot from 2021-02-24 07-21-09.png

On Spring initializr choose a gradle project with dependencies:

  • Spring Web
  • Spring Boot DevTools
  • Prometheus
  • Spring Boot Actuator

The final code is available on this Github repository.

Expose Prometheus metrics

On your application.properties file, add the following line:

management.endpoints.web.exposure.include=* 
Enter fullscreen mode Exit fullscreen mode

Run your Spring application and access the endpoint:

http://localhost:8080/actuator/prometheus 
Enter fullscreen mode Exit fullscreen mode

It should return a bunch of data in a format that is understandable by Prometheus.

Configure Prometheus to scrap this data

On your prometheus.yml file, add a new job under scrape_configs:

global:   scrape_interval: 10s  scrape_configs:   - job_name: 'spring_micrometer'     metrics_path: '/actuator/prometheus'     scrape_interval: 5s     static_configs:       - targets: ['localhost:8080'] 
Enter fullscreen mode Exit fullscreen mode

Now access Prometheus interface on http://localhost:9090/ and query for

http_server_requests_seconds_count{job="spring_micrometer"} 
Enter fullscreen mode Exit fullscreen mode

Screenshot from 2021-03-01 06-58-17.png

You will see the requests Prometheus is making to scrap data from your Spring boot application. That's a signal that everything is working so far.

Configure Grafana

Now we will configure Grafana to display this data. Open Grafana on your browser and import the JVM (Actuator) dashboard.

Screenshot from 2021-03-01 07-07-16.png

You should now see some cool data:
Screenshot from 2021-03-01 07-09-25.png

Conclusion

Now you have all your metrics in one place, just need to enter an URL from your browser. You could even buy a giant TV and keep the dashboard streaming 24/7.

What if you could send your own custom metric to Prometheus, like a business metric? What if you could create automated alerts based on Prometheus queries? Leave a comment below so I will know you're interested in these contents.

devopsjavatutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.