依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId>
<version>0.2.2</version>
</dependency>
启动类 增加Bean
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(
@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.config ().commonTags ("application", applicationName);
}
yaml配置文件
management:
endpoints:
web:
exposure:
include: info,health,prometheus
#
spring:
application:
name: monitor
启动应用
访问地址:http://localhost:8080/actuator/prometheus
scrape_configs 添加新的监控任务,然后 重启 Prometheus!
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "node_export"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["192.168.111.101:9100"]
- job_name: "boot-prometheus"
scrape_interval: 2s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ["192.168.1.5:8080"]
http://192.168.111.101:9090/targets
:正常!!
访问地址:http://192.168.111.101:3000/
,SpringBoot应用监控用 10280
效果图
鼠标放在某一块,按 v 放大查看