SpringBoot+Prometheus+Grafana realizes system visual monitoring

Scenes

Actuator is integrated in SpringBoot to monitor the running status of the system:

Integrating Actuator in SpringBoot to monitor the running status of the system

Based on the above Actuator to realize system monitoring, the following solutions can also be adopted.

Prometheus

Prometheus is an open source toolkit for system monitoring and alerting, which uses the Pull method to collect time-series measurement data (also supports the push method),

Transmission through Http protocol. The way it works is that the service being monitored needs to expose a Prometheus endpoint, which is an HTTP interface,

This interface exposes the list of metrics and current values, and then the Prometheus application regularly pulls data from this interface, which can generally be stored in a time series database.

Then display the data through the visualized Dashboard (egGrafana).

Grafana

Grafana is an open source dashboard display tool that can support many mainstream data sources, including sequential and non-sequential.

The display configuration and scalability it provides meet most of the time series data display needs, and it is an excellent tool.

Note:

Blog:
Domineering Rogue Temperament_C#, Architecture Road, SpringBoot-CSDN Blog

accomplish

1. Create a new SpringBoot project and add dependencies

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- prometheus support -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

2. Modify the yml file and add the following configuration

management:
  metrics:
    export:
      prometheus:
        enabled: true
        step: 1m
        descriptions: true
  web:
    server:
      auto-time-requests: true
  endpoints:
    prometheus:
      id: springmetrics
    web:
      exposure:
        include: health,info,env,prometheus,metrics,httptrace,threaddump,heapdump,springmetrics

# 开发环境配置
server:
  # 服务器的HTTP端口,默认为8080
  port: 996
  servlet:
    # 应用的访问路径
    context-path: /
  tomcat:
    # tomcat的URI编码
    uri-encoding: UTF-8
    # tomcat最大线程数,默认为200
    max-threads: 800
    # Tomcat启动初始化的线程数,默认值25
    min-spare-threads: 30

Note that the port configured here is 996

3. Start the project and visit

http://127.0.0.1:996/actuator/prometheus

That is, you can see the exposed information

 

4. Download and install Prometheus

download link:

Download | Prometheus

This is on windows, so choose the zip package corresponding to windows

 

Of course, there are other ways to download and install, such as docker.

If the official website cannot be downloaded for a long time, you can search for the corresponding windows package from the Internet to download and decompress it.

After decompression, find prometheus.yml and modify the metrics_path in the configuration file to the corresponding path and targets to the corresponding ip and port.

 

For more configuration instructions, refer to the official documentation

https://github.com/prometheus/prometheus/blob/main/documentation/examples/prometheus.yml

After modifying the configuration file, double-click prometheus.exe to start, then wait for the startup to succeed and access the default port 9090

http://localhost:9090

Enter in Expression

jvm_memory_used_bytes

Then check the monitoring effect

 

5. Download and install Grafana

download link:

Index of grafana-local

 

After downloading and decompressing, find grafana-server.exe under the bin and double-click to start

 

Access after successful startup

http://127.0.0.1:3000/login

 

The default account is admin, and the password is also admin

6. After logging in and being prompted to change the password, click DATA SOURCES

Then add the data source type as Prometheus

 

Enter the corresponding address started above

 

7. Click on the upper right corner to create a New dashboard

 

Then click Add visualization

 

Then select the data source you just added

 

Then select a parameter such as jvm_buffer_count_buffers below, and set other parameters according to your needs, save and view.

 

Guess you like

Origin blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/131931722