一、SpringBoot配置.
①、引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
②、开启监控
management:
endpoints:
web:
exposure:
include: prometheus
③、启动服务,查看监控采集:
http://test.code.com/skywalk/actuator/prometheus

二、定义Prometheus监控任务.
①、prometheus.yml
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: 'Windows'
static_configs:
- targets: ['192.168.1.6:9182']
labels:
instance: Windows
# 新添加的采集目标
- job_name: "skywalk-boot"
metrics_path: '/skywalk/actuator/prometheus'
static_configs:
- targets: ["192.168.1.6:80"]
②、启动prometheus

③、 查看界面

三、启动Grafana
①、直接启动即可.
springboot监控面板,推荐第一个非常不错.

本文详细介绍了如何在SpringBoot应用中配置Prometheus监控,并通过Grafana展示监控数据。首先,通过引入相关依赖并配置Actuator以启用监控接口。接着,配置Prometheus的`prometheus.yml`文件,添加新的监控目标。然后,启动Grafana并展示监控面板。此外,文章还深入解析了HikariCP数据库连接池的监控指标,包括连接数、活跃连接、空闲连接等,帮助理解数据库连接池的运行状态。
最低0.47元/天 解锁文章
882





