1 introduction

The more I worked on the project, the more I realized that operation and maintenance monitoring was too important for any system to go online. As for the monitoring of Springboot micro-service, I have previously written [Springboot] to monitor your micro-service application with Springboot Admin. This solution can monitor and provide alarm reminder function in real time, but cannot record historical data, and cannot view the operation and maintenance status of the past hour or the past day. This paper introduces Prometheus + Grafana method to monitor Springboot 2.X and realize beautiful data visualization.

2 Prometheus

Prometheus is an excellent open source monitoring, alarm, and time series database combination system, which is commonly used with Prometheus in the most common Kubernetes container management system.

2.1 Importing Springboot

Introducing Prometheus into dependencies as follows:

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>Copy the code

For Springboot, use the Actuator and open the corresponding Endpoint:

Management. Endpoints. Web. Exposure. Include = * # or management endpoints. Web. Exposure. Include = PrometheusCopy the code

After Springboot is started, you can use the following URL to check whether monitoring data can be obtained correctly:

localhost:8080/actuator/prometheusCopy the code

If data is successfully obtained, Springboot can provide monitoring data.

2.2 Docker Mode

For convenience, start Prometheus with Docker:

Docker pull PROM/PrometheusCopy the code

Prepare the configuration file prometheus.yml:

Scrape_configs: # scrape_timeout: 1 10s # Path metrics_PATH: '/ skeletonoid/Prometheus' # IP address of the target server using Springboot static_configs: - targets: ['hostname:9000','hostname:8080']Copy the code

Start docker instance:

# port is 9090. Specify the configuration file docker run - d - 9090: p - 9090 - v/temp/Prometheus. Yml: / etc/Prometheus/Prometheus yml PROM/Prometheus --config.file=/etc/prometheus/prometheus.ymlCopy the code

2.3 Test and View

After successful startup, you can open the web page to view, and can be graphically displayed, the URL is http://localhost:9090/.

As shown in the figure above, after opening the web page, randomly select a corresponding monitoring indicator and parameter, and click Execute to view it.

3 Grafana

Grafana is an open source metrics analysis and visualization suite, a front-end tool for pure JavaScript development that displays custom reports, display charts, and more by accessing libraries such as InfluxDB. Its UI is very flexible, with rich plug-ins and templates, powerful. Generally used in the monitoring of time series data.

3.1 Docker installation and startup

Docker run -d -p 300:3000 grafana/grafana docker run -d -p 300:3000 grafana/grafanaCopy the code

After the startup is successful, visit http://localhost:3000 to check whether it is successful. The initial password of the administrator account is admin and admin.

3.2 Configuring a Data Source

If Grafana displays data, the corresponding data source needs to be configured. In this article, the Prometheus data source installed before is configured, as shown in the figure below:

Note that Browser mode must be selected for Access, otherwise data cannot be normally obtained. Once the configuration is complete, click Save & Test.

3.3 Template Application

Once the data is available, you can customize the visualization of the data. But if you add an index an index, it will be very troublesome. In fact, Grafana provides many excellent templates available at grafana.com/grafana/das… Lookup.

In this article, the Spring Boot 2.1 Statistics template is used, and the import method is as follows:

Click the + sign –> Import –> enter the template link or ID –> Load.

After successful import, you can monitor the data, and the interface is really nice:

4 summarizes

This article describes how to use Prometheus + Grafana to monitor Springboot applications, and Prometheus + Grafana is actually powerful enough to be worth the time.

The software version information in this example is as follows:

Springboot. Version = 2.2.5 micrometer - registry - Prometheus = 1.3.5 Prometheus, version = 2.16 grafana. Version = 6.7.0 - walkCopy the code

Welcome to pay attention to the public number “pumpkin slow talk”, will continue to update for you…

Read more and share more; Write more. Organize more.