1 Introduction
The more the project progresses, the more I feel that operation and maintenance monitoring is too important for any system that goes online.
Prometheus is an excellent open source monitoring, alarm and time series database combination system. In the most common Kubernetes
container management system, it is usually paired with Prometheus
Monitor.
2.1 Introduction to Springboot
Introduce Prometheus
into dependencies as follows:
<dependency> <groupid>io.micrometer</groupid> <artifactid>micrometer-registry-prometheus</artifactid> </dependency>
For Springboot, enable Actuator
and open Corresponding Endpoint
:
management.endpoints.web.exposure.include=* # 或者 management.endpoints.web.exposure.include=prometheus
After starting Springboot
, you can check whether the monitoring data can be obtained correctly through the following URL:
localhost :8080/actuator/prometheus
The data is obtained successfully, indicating that Springboot
can provide monitoring data normally.
2.2 Using Docker
For convenience, use Docker
to start Prometheus
:
# 拉取docker镜像 docker pull prom/prometheus
Preparation Configuration file prometheus.yml
:
scrape_configs: # 可随意指定 - job_name: 'spring' # 多久采集一次数据 scrape_interval: 15s # 采集时的超时时间 scrape_timeout: 10s # 采集的路径 metrics_path: '/actuator/prometheus' # 采集服务的地址,设置成Springboot应用所在服务器的具体地址 static_configs: - targets: ['hostname:9000','hostname:8080']
Start the docker instance:
# The port is 9090, specify the configuration file
docker run -d -p 9090 :9090 -v ~/temp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml
2.3 Testing and Viewing
After successful startup, you can open the web page to view it and display it graphically. The URL is http://localhost:9090/.
As shown in the picture above, after opening the web page, select a corresponding monitoring indicator and parameter and click Execute
to view it.
3 Grafana
Grafana
is an open source measurement analysis and visualization suite, a front-end tool developed purely in JavaScript
. Display custom reports, display charts, etc. by accessing libraries (such as InfluxDB
). Its UI is very flexible, rich in plug-ins and templates, and powerful. Generally used in monitoring time series data.
3.1 Docker installation and startup
# 拉取镜像 docker pull grafana/grafana # 运行实例 docker run -d -p 3000:3000 grafana/grafana
After successful startup, visit http://localhost:3000 to check whether it is successful. The initial administrator account password is admin /admin
.
3.2 Configure the data source
Grafana
To display data, you need to configure the corresponding data source. In this article, configure the that was installed and enabled before. Prometheus
data source, the specific configuration is shown in the figure below:
It should be noted that Access
must select Browser
mode , otherwise the data cannot be obtained normally. After the configuration is completed, click Save & Test
.
3.3 Template application
After you can obtain the data, you can customize the data visualization display. But if you add one indicator at a time, it will be very troublesome. In fact, Grafana
provides many excellent templates, which can be found on the web page https://grafana.com/grafana/dashboards.
This article uses the Spring Boot 2.1 Statistics template. The import method is as follows:
Click on the
number--> Import
- -> Enter the template link or ID --> Click Load.
After successful import, you can monitor the data, and the interface is really nice:
Example in this article The software version information is as follows:
springboot.version=2.2.5 micrometer-registry-prometheus=1.3.5 prometheus.version=2.16 grafana.version=6.7.0-beta1
The above is the detailed content of How to use Prometheus+Grafana to monitor Springboot applications. For more information, please follow other related articles on the PHP Chinese website!