This article uses docker to deploy prometheus+grafana to monitor various indicator data of the application system. The springboot application exposes the metrics data through the actuator integrated micrometer, prometheus is responsible for collecting the metrics data exposed by the application, and grafana is responsible for graphically displaying the data source data. It is relatively simple and the content is as follows.
1. Environment description
The springboot used in this article is 2.7+, the docker image of each component is latest, and the docker host environment is virtualbox virtual machine.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. Precautions
It is recommended to close the firewall of the host machine first, otherwise, close the firewall during the deployment of docker, docker will have a security check, and docker needs to be restarted.
The springboot application depends on actuator+micrometer. If there is a security component, please allow the interface address that exposes data (/actuator/prometheus).
3. To deploy docker
and start prometheus, you need to specify the configuration file. Simple configuration: prometheus.yml simple configuration. The path where this article is placed: /root/prometheus
global:
scrape_interval: 15s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'star'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
scheme: http
static_configs:
- targets: ['192.168.1.1:8080']
Here metrics_path needs to be specified (the default is /metrics which does not match the number). The remaining operations are to pull the docker image and start it. Visit prometheus targets and check the exposed address of your application. If the status is up, it is ok.
4. Configure grafana
to access the grafana address and add the prometheus data source.
With the data source, you can create a new panel in Dashboards, or you can import the template through import (search the official website to import the available templates), and select the target data source to display the chart.