一. 搭建prometheus
- 在springboot项目中:
在 pom.xml 中添加如下配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
- 然后修改 application.yaml 中添加 Spring Boot Actuator 相关配置:
spring:
application:
name: spring-boot-demo
management:
endpoints:
web:
exposure:
include: "*"
health:
show-details: always
metrics:
export:
prometheus:
enable: true
tags:
application: spring-boot-demo
- 可以通过 /actuator/prometheus 接口查看配置是否正确
curl 'http://localhost:8080/actuator/prometheus' -i -X GET
- 下载对应版本prometheusDownload | Prometheus并解压
tar xvfz prometheus-2.37.0.linux-arm64.tar.gz
- 在 prometheus.yml 中添加上 Service 对应的任务
scrape_configs:
- job_name: 'springboot-app-smart_hospital'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:30090']
- 运行./prometheus,测试访问9090端口
- 编辑服务
vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Time Series Collection and Processing Server
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/root/prometheus/prometheus-2.37.0.linux-arm64/prometheus \
--config.file /root/prometheus/prometheus-2.37.0.linux-arm64/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/root/prometheus/prometheus-2.37.0.linux-arm64/consoles \
--web.console.libraries=/root/prometheus/prometheus-2.37.0.linux-arm64/console_libraries
[Install]
WantedBy=multi-user.target
- 依次执行
systemctl daemon-reload
systemctl restart prometheus.service
systemctl status prometheus.service
systemctl enable prometheus
二. 搭建node_exporter
- 下载对应版本prometheus-node_exporterDownload | Prometheus并解压
tar xvfz node_exporter-1.3.1.linux-arm64.tar.gz
- 编辑服务
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
PIDFile==/var/run/node_exporter.pid
ExecStart=/root/node_exporter/node_exporter-1.3.1.linux-arm64/node_exporter
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
- 启动服务
systemctl daemon-reload
systemctl restart node_exporter
systemctl status node_exporter
systemctl enable node_exporter
- 配置prometheus
vim prometheus.yml
- job_name: "node_exporter"
static_configs:
- targets: ["localhost:9100"]
- 重启prometheus
systemctl daemon-reload
systemctl restart prometheus.service
systemctl status prometheus.service
三. 搭建grafana
- 依次执行
sudo apt-get install -y adduser libfontconfig1
wget https://dl.grafana.com/enterprise/release/grafana-enterprise_9.0.5_arm64.deb
sudo dpkg -i grafana-enterprise_9.0.5_arm64.deb
systemctl daemon-reload
systemctl restart grafana-server
systemctl status grafana-server
systemctl enable grafana-server
- import模板8919(node_exporter),4701(JVM)