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.
If you want to know how to install Prometheus and Grafana on a Linux based OS, check my previous article.
On Spring initializr choose a gradle project with dependencies:
Spring Boot DevTools
Spring Boot Actuator
The final code is available on this Github repository.
application.properties file, add the following line:
Run your Spring application and access the endpoint:
It should return a bunch of data in a format that is understandable by Prometheus.
prometheus.yml file, add a new job under
global: scrape_interval: 10s scrape_configs: - job_name: 'spring_micrometer' metrics_path: '/actuator/prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:8080']
Now access Prometheus interface on
http://localhost:9090/ and query for
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.
Now we will configure Grafana to display this data. Open Grafana on your browser and import the JVM (Actuator) dashboard.
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.