This tutorial provides a complete guide on how to monitor an API on your local system using a visualizing tool Grafana.
We will be integrating Spring Boot Actuator into Prometheus then, visualizing and monitoring on Grafana
Spring Boot Actuator generates metrics for our API which prometheus queries and binds to grafana where it is visualized and monitored.
SPRING BOOT ACTUATOR provides production-ready features such as metrics gathering, HTTP tracing etc.these features can be accessed over JMX or HTTP endpoints and can be integrated with external application monitoring systems like Prometheus, Graphite etc. read more
Integrating Spring Boot actuator into our application.
The prometheus endpoint is exposed by Spring Boot when micrometer-registry-prometheus dependency is available on the classpath.
Check out how to integrate Spring boot Actuator into your Application here
I have integrated spring boot actuator to a simple Api i created on my local system.
You can get the the application we used for the Prometheus setup from this GitHub repository.
- Run your application on your Local IDE.
- Then configure Prometheus to query the application and get results.
The prometheus endpoint exposes metrics data in a format that can be scraped by a Prometheus server. You can see the exposed metrics data by navigating to the prometheus endpoint (http://localhost:8080/actuator/prometheus).
PROMETHEUS is a time-series database and an open source monitoring system.read more
Download and configure Prometheus
-First download Prometheus
-Extract to your selected directory
-To configure your application to be monitored, In the prometheus folder,
you can either use the sample prometheus.yml file or create new .yml
*Below is the configuration of a new file i have created*
-Run prometheus server using the command prometheus.exe --config.file=YAML_FILE_PATH.
Browse the URL http://localhost:9090/ to test the prometheus sever. If you see the page below, Prometheus server running fine and scraping the metrics which is based on the configuration you made using tutor.yml on starting the server.
GRAFANA is an open source software used for visualizing, monitoring and analysing data performances.It has very beautiful visual representations and supports different datasourses.read more
Download and configure Grafana
- Download Grafana
- Extract files to desired directory
- In the extracted grafana folder,open the "conf" directory,configurations can be done in the ".ini" files, To avoid complications, we will continue with the default settings.which will configure "admin/admin" as the username and password.
- In the"bin" directory of the Grafana folder. Run the server by executing grafana-server.exe
- Now you can log in to Grafana inputing http://localhost:3000 in your
Remember username and password are "admin/admin". You can change this anytime using the .ini file we discussed earlier.
- On the Home page Click on "create your first data source". This will open a page to add a data source.
- Select Prometheus as the datasource
- Give a suitable name to the data source.
- Select Prometheus as the "type".
- The URL should be "http://localhost:9090" since we have Prometheus running
on port 9090.
Build your Grafana Dashboard
- You can create your own dashboard or import dashboard
- Click on the "+" option on the left menu of the home screen to create or import a dashboard.
-Our metrics will be populated in the graph
You can now add more queries to your dashboard.
API Monitoring is important to gain visibility into performance, availability and functional correctness.Creating dashboards on Grafana helps us quickly address errors, check the health of our application, if an application is responding correctly and if the service is accessible at all time etc.
Using spring boot actuator to generate and customize your metrics and Prometheus to query these metrics and visualize them on Grafana, Has made monitoring an application quite easy.