Spring Boot Monitoring with Prometheus and Grafana

Spring Boot System and Service Monitoring with Prometheus and Grafana Hi. Welcome to the continuation of my Spring boot monitoring tutorial....


Spring Boot System and Service Monitoring with Prometheus and Grafana

Hi. Welcome to the continuation of my Spring boot monitoring tutorial.

With Spring boot actuator we already have production-ready metrics, health check-ups, auditing and more as discussed in the previous blog. In this entry, we will learn how we can integrate 2 of the most popular 3rd party libraries use in monitoring.
  1. Prometheus - an open-source system and service monitoring. It collects metrics on a given interval. Thus, it is mostly used in collecting time-series data.
  2. Grafana - an open-source charting software for time-series analytics.

Configuring the Project

With micrometer, Spring is able to integrate application metrics to an external monitoring system such as Prometheus. For more documentation please refer to the link in the reference section.

To integrate micrometer in a Spring project we just need to add a micrometer dependency. See the code below.

It collects and export application metrics in an HTTP endpoint. The application data exposed by this endpoint is formatted in such a way that Prometheus server can scrape it.

Let’s run the Spring application and see the Prometheus metrics by opening the URL SERVER/actuator/prometheus.

Running Prometheus

We will be running Prometheus using Docker. For the image documentation please see the link in the reference section below. But before we do that we first need to define the prometheus.yml configuration. So download a base copy of that file from https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus.yml and add a new job_name entry under scrape_configs:

- job_name: 'spring-actuator'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
    - targets: [SPRING_HOST_IP:8080']

Of course, don’t forget to update the static_configs.targets value which should point to where you install your Prometheus server, normally the default should be fine. Unless you change something in your network config or port.

To run Prometheus execute:

docker run -p 9090:9090 -v /home/czetsuya/project/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

The first parameter of the -v argument must be the path of the prometheus.yml file that you have downloaded and modified. prom/prometheus is the container. See the link in the reference section for more information.

Now fire up the browser and see what we can do. Open PROMETHEUS_HOST:9090. In the query section, we can monitor different metrics such as the number of HTTP requests and CPU usage. We can also change how frequent the graph should update.


Running Grafana

Running Grafana is almost the same way with Prometheus, with Docker we just need to execute the command in the terminal below.

docker run -p 3000:3000 grafana/grafana

Now let’s access the URL GRAFANA_HOST:3000. The default username and password is admin, on the first login, it should ask you to change your password for security reasons.

Inside the Grafana interface we need to:
  1. Add dashboard
    1. Create query
    2. Select Graph
    3. Update properties

References

COMMENTS

mas template
Name

amazon,1,angular,8,bigdata,2,business,1,course-spring,27,courses,6,database,4,docker,3,java,50,kafka,1,keycloak,4,microservices,5,mysql,1,neworking,1,nosql,2,php,1,pinned,2,react,3,server management,7,shared drive,1,spring,7,synology,1,troubleshooting,2,web,1,wordpress,1,
ltr
item
toztech: Spring Boot Monitoring with Prometheus and Grafana
Spring Boot Monitoring with Prometheus and Grafana
https://i.ytimg.com/vi/56FNz6CMNAU/0.jpg
https://i.ytimg.com/vi/56FNz6CMNAU/0.jpg
toztech
https://toztech.blogspot.com/2019/08/spring-boot-monitoring-with-prometheus.html
https://toztech.blogspot.com/
https://toztech.blogspot.com/
https://toztech.blogspot.com/2019/08/spring-boot-monitoring-with-prometheus.html
true
2554149350007112447
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content