Prometheus + Grafana监控springboot应用
本示例适用于无注册中心的简单场景
应用程序配置
-
引入依赖
gradleimplementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-registry-prometheus'
maven
<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: endpoint: prometheus: enabled: true metrics: export: prometheus: enabled: true tags: application: ${spring.application.name} endpoints: jmx: exposure: exclude: "*" web: exposure: include: "*"
Prometheus
prometheus.yml
添加job,指向每个应用节点的http地址:scrape_configs: - job_name: 'application_exporter' metrics_path: /actuator/prometheus static_configs: - targets: - 192.168.3.220:8084 - 192.168.1.10:8084
Grafana
导入dashboard模板
system-monitor_rev2.json-
查看效果