Prometheus
安装
下载:https://github.com/prometheus/prometheus/releases/download/v2.29.1/prometheus-2.29.1.linux-amd64.tar.gz
上传到服务器,解压
1
2tar -xvzf prometheus-2.29.1.linux-amd64.tar.gz
mv prometheus-2.29.1.linux-amd64 prometheus安装node_exporter,下载:https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
上传到服务器,解压并启动
1
2
3
4
5tar -zvxf node_exporter-1.3.1.linux-amd64.tar.gz
mv node_exporter-1.3.1.linux-amd64/ node_exporter
nohup /usr/local/node_exporter/node_exporter &
检查是否启动
netstat -nltp |grep 9100修改Prometheus配置文件prometheus.yml
启动
1
2
3./prometheus --config.file="prometheus.yml" &
检查是否启动
ps -ef |grep prometheus
使用
访问地址:http://192.168.0.153:9090/
Targets
点开 http://192.168.0.153:9100/metrics,展示各种指标
Graph
上面的指标可以在这里以表格/折线图的形式查询
Grafana
安装
下载:https://dl.grafana.com/oss/release/grafana-9.2.3.linux-amd64.tar.gz
上传到服务器,解压
1
2tar -zvxf grafana-9.2.3.linux-amd64.tar.gz
mv grafana-9.2.3/ grafana/创建Grafana服务
1
2
3
4
5
6
7
8
9
10
11cat > /usr/lib/systemd/system/grafana-server.service <<EOF
[Unit]
Description=Grafana
After=network.target
[Service]
Type=notify
ExecStart=/usr/local/grafana/bin/grafana-server -homepath /usr/local/grafana
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF启动
1
2systemctl enable grafana-server.service
systemctl start grafana-server.service
使用
http://192.168.0.153:3000/
默认账户/密码:admin/admin
配置数据源
导入Dashboard
如导入id为9276的Dashboard:https://grafana.com/grafana/dashboards/9276-1-cpu/
整合SpringBoot应用
引入依赖
1
2
3
4
5
6
7
8
9<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.2</version>
</dependency>增加配置
1
management.endpoints.web.exposure.include=*
开放actuator endpoint
重启,检查actuator endpoint是否生效
修改Prometheus配置
1
2
3
4
5
6
7
8
9
10
11scrape_configs:
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090","192.168.0.153:9100"]
- job_name: "data-fill"
scrape_interval: 5s #每5s抓取一次
metrics_path: '/api/actuator/prometheus' #抓取的数据url
static_configs:
- targets: ["192.168.0.153:6868"]导入Dashboard
id:4701 https://grafana.com/grafana/dashboards/4701-jvm-micrometer/