Monday, April 19, 2021

Spring Boot - Prometheus - Grafana

In this post we will learn how to monitor our gateway-server using Prometheus and Grafana. First we need to add dependency to micrometer-registry-prometheus in our maven pom.xml file as shown below.



Next we need to expose actuator prometheus in our application.properties file as shown below.



We have finished making additional config in our gateway-server project. Now we can open browser and check if actuator prometheus is available using gateway-server actuator url http://localhost:9899/actuator/prometheus.



Now we need to download and run prometheus from its website here. Extract it and go to its home directory as shown below. In it, you'll find prometheus.yml file which we need to modify.



Add the following gateway-actuator job inside the prometheus.yml. By default, prometheus includes a job named prometheus that can be accessed using url http://localhost:9090/metrics. Our gateway-actuator job's static config target points to our gateway application host and port. It also mentioned our actuator prometheus using metrics path /actuator/prometheus.


We can now run the prometheus from command prompt as shown below. Just type prometheus inside the prometheus home directory.


Next we can point out our browser to http://localhost:9090/metrics.


We can also point out to http://localhost:9090/graph to see the graph version of the metrics.


We can choose metrics http_server_requests_seconds_count and our gateway request count will be displayed:


Now we need to download and install grafana from its website here. The website also contains good documentation on how to get started using grafana. As mentioned in the getting started page, we can go to browser url http://localhost:3000/login and log in using default username and password admin admin. The grafana homepage is shown below after successfully logged in.


Next thing to do is to create a grafana data source by clicking below link.


In the Add Data Source page, choose Prometheus.


In the Configure Prometheus Data Source page, specify our prometheus host and port as shown below.


Next thing is to create dashboard by clicking link below:


In the New Dashboard page, add metrics that we want to see the graph. In this example we will add metrics http_server_requests_seconds_count as shown below.


The graph is displayed below:


The newly created dashboard is shown below:



0 comments:

 

©2009 Stay the Same | by TNB