前言
采用docker模式安装,先pull
docker pull prom/prometheus
docker pull grafana/grafana
springboot
在pom里增加
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.5.1</version>
</dependency>
注意:springboot不同版本对应的,io.micrometer是不一样的。
springboot 2.3对应 io.micrometer 1.5.x
springboot 2.4对应 io.micrometer 1.6.x
在application.yml里增加
management:
endpoints:
web:
exposure:
include: '*'
metrics:
export:
prometheus:
enabled: true
tags:
application: ${spring.application.name} # 暴露的数据中添加application label
启动项目,访问:http://localhost:8080/actuator/prometheus, 能看到对应信息,如果遇到404,请参考上面的版本对应关系
prometheus
安装参考下面的链接,我用的docker, 在机器上定义 prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.1.101:9090']
- job_name: 'java-fx-control'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['192.168.1.101:8288']
启动命令,映射了docker里的prometheus.yml到物理机上
echo "stop prometheus"
docker stop prometheus
docker rm prometheus
echo "stop prometheus"
echo "start prometheus"
docker run -d -p 9090:9090 \
-v /root/env/prometheus.yml:/etc/prometheus/prometheus.yml \
--name prometheus \
prom/prometheus:latest
打开链接查看 http://192.168.1.101:9090/targets
Grafana
编写 restart-grafana.sh命令
echo "stop grafana"
docker stop grafana
docker rm grafana
docker run -d \
-p 3000:3000 \
--name=grafana \
-v /root/env/grafana-storage:/var/lib/grafana \
grafana/grafana
~
后续参考:https://www.cnblogs.com/larrydpk/p/12563497.html
参考:
【Springboot】用Prometheus+Grafana监控Springboot应用
micrometer埋点(Spring boot 2.X metrics)
给你的SpringBoot做埋点监控--JVM应用度量框架Micrometer