一、Prometheus集成
1、再pom文件中添加如下配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
2、添加yum配置文件
management:
server:
port: 11001
endpoints:
web:
exposure:
include: prometheus,health
3、在启动类中添加入下代码,用于注册统一tag名,便于查询
方案1:添加配置文件 (低版本没tags属性:譬如 2.0.9.RELEASE)
方案2:注册代码
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName){
return registry -> registry.config().commonTags("application", applicationName);
}
4、启动项目访问:http://127.0.0.1:11001/actuator/prometheus
二、Prometheus监控
1、下载Prometheus
官网:https://prometheus.io/download/
地址:https://prometheus.io/download/prometheus-2.21.0.linux-amd64.tar.gz
2、 解压并修改配置
修改 prometheus.yml
scrape_configs:
- job_name: 'prometheus-job1'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['127.0.0.1:11001']
3、启动Prometheus
./prometheus --config.file="prometheus.yml" &
4、访问 http://192.168.158.200:9090/targets
三、配置Grafana 监控
1、 下载Grafana
官网:https://grafana.com/grafana/download?platform=linux
地址:https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz
2、解压启动grafana
bin/grafana-server &
3、访问 http://192.168.158.200:3000/
1)、添加Prometheus数据源
2、添加监控DashBoard
1)添加监控 JVM 的 Dashboard ,导入模板编号为 4701
1)添加自定panel,点击右上角添加新panel
以上!!!