1. Introduction

Recently, more and more feel that any system online, operation and maintenance monitoring is too important. This paper introduces Prometheus + Grafana method to monitor Springboot 2.X and realize beautiful data visualization.

2. Add monitoring

Spring-boot-actuator Module helps you monitor and manage your applications as they go into production. You can choose to use HTTP endpoints or JMX to manage and monitor your application. Auditing, health, and metrics Gathering can also be automatically applied to your application. Import dependencies as follows:


     

    <! -- Monitoring alarm -->

    <dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-actuator</artifactId>

    </dependency>

    <dependency>

    <groupId>io.micrometer</groupId>

    <artifactId>micrometer-registry-prometheus</artifactId>

    </dependency>

Copy the code

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


     

    # Prometheus configuration

    info:

    alen:alen

    management:

    endpoints:

    web:

    base-path:/actuator

    exposure:

    include:"*"

Copy the code

After startup Springboot, can use the following URL can get right to the monitoring data: localhost/physical/Prometheus to obtain data, explain Springboot provide monitoring data properly.

Primary endpoint

3. The configuration of Prometheus

Prometheus, a system and service monitoring system, is a project of the Cloud Native Computing Foundation. It collects metrics from configured targets at a given time interval, evaluates regular expressions, displays results, and triggers an alert if certain conditions are observed to be true.

features


     

    • Multidimensional data model (time series defined by measure name and key/value dimension set)

    • Flexible query language to take advantage of this dimension

    • Do not rely on distributed storage; Individual server nodes are autonomous

    • Time series collection occurs through pull Models over HTTP

    • Push time series are supported through an intermediate gateway

    • Target discovery through service discovery or static configuration

    • Multiple modes of graphics and dashboard support

    • Support for hierarchical and horizontal federation

Copy the code

Using Prometheus to capture data Prometheus pulls indicator data promethe. yml in the endpoints (/actuator/ Prometheus) that are exposed according to the configured period


     

    - job_name: 'actuator-ruoyi'

    # metrics_path defaults to '/metrics'

    # scheme defaults to 'http'.

    metrics_path: '/actuator/prometheus'

    static_configs:

    - the targets: [' 10.42.95.4]

Copy the code

Restart Prometheus, access the site of Prometheus, and check whether targets starts normally as shown in the figure below

4. Add monitoring templates to Grafana

The default Grafana address is http://localhost:3000/, the login user name and password are admin/admin, and the import configuration is Grafana ID = 4701

The final result looks like this, as shown below

5. Note

Problem: Add-on cannot access the Endpoint? Solution: The reason is that shiro for the project needs to add filtering


     

    filterChainDefinitionMap.put("/actuator/**","anon");

Copy the code

Problem two:


     

    /O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Broken pipe

Copy the code

Resolution: The cause of this error is that project.artifactid may contain uppercase. I’ll just change it to lowercase