preface

The rocketMQ cluster setup in the previous article was originally intended to write kafka cluster setup, but it seems that the two things are similar. In addition, I only have an Ali cloud server, and there is no virtual machine installed locally, so even if I build a cluster, it is a fake cluster. So I thought about giving up. This article mainly introduces how to build a monitoring system using Prometheus and Grafana in springboot environment.

Create a SpringBoot project

Create a new SpringBoot project and add the Actuator dependencies in the POM

The purpose of this dependency package is to expose the endpoint of the monitoring.

Start the project, visit http://localhost:8080/actuator

However, since 2.0, not all endpoints are exposed by default. To expose all endpoints, add a sentence in the configuration file.

And then revisit

This exposes all the endpoints. You also need to add a dependency package that exposes the endpoints to the Prometheus format

Post add accesshttp://localhost:8080/actuator/peometheus

That’s all Prometheus needed.

Two structures, Prometheus

Promethues are created in the way of Docker

Create Prometheus directory, store Prometheus. yml, and create Prometheus. yml

Then run the following command

docker run \
-p 9090:9090 \
-v /liuxc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
--name prometheus-9090 prom/prometheus
Copy the code

He downloads the Prometheus image, runs it, and checks whether it is running successfully.

Then access port 9090, as shown below

Prometheus has started successfully. But now it has no connection with our Springboot service, so how does it collect our micro service data, need to modify the configuration file. Because my local network is not public network, Ali cloud server can not connect to my local IP, so I need to upload springboot project into jar package to Ali Cloud server, before uploading SPRINGboot port set to 8099, Java-jar start, and then modify Prometheus configuration file

Then delete the container you ran before, run it again, and access port 9090

Which means Prometheus is already collecting our microservices. But Prometheus’s page presentation isn’t very friendly, and we’ll do it using the Grafana tool.

Three installation grafana

Similarly, we also install Grafana through docker

docker run -d --name=grafana-3000 -p 3000:3000 grafana/grafana
Copy the code

Then access port 3000

The default grafana user name and password are admin, and the interface is as follows

How does grafana relate to Prometheus? This will require configuring grafana’s data source as shown in the following figure

Then we set up a dashboard to look at some information about the JVM

However, it is not possible to build dashboards one by one. Grafana has actually provided us with a solution to how to create dashboards for each metric. The 4701 template is introduced, but you need to add a bean to the SpringBoot project, as shown on the official website

I’ll put it in the project, but I’ll call it Demo3, repackage it, upload it and start it.

Grafana imports template 4701.

Enter a name and select PrometheusAfter import, as shown in the figure below, each indicator will come out.

At this point, Prometheus + Grafana monitors the Springboot service.

Four summarizes

In fact, there are many things that need to be set up, such as Node-Exporter monitoring server information, AlertManager monitoring alarms and so on, but I want to add Node-exporter and AlertManager functions next week. So Prometheus plus Grafana plus AlertManager, from monitoring to alerting. See you next week.