一、springboot
1、pom
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <scope>runtime</scope> </dependency>
2、yml
spring: application: name: PrometheusApp #Prometheus springboot监控配置 management: endpoints: web: exposure: include: '*' metrics: export: prometheus: enabled: true tags: application: ${spring.application.name} # 暴露的数据中添加application label
3、访问
http://localhost:8080/actuator/prometheus
二、prometheus
1、官网下载安装
prometheus-2.37.8.windows-amd64
2、配置文件
- job_name: "windows-exporter"
static_configs:
- targets: ["localhost:9182"]
- job_name: 'PrometheusApp'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
3、启动访问
http://localhost:9090/targets?search=
三、exporter
1、下载启动
windows_exporter-0.23.1-amd64.exe
2、访问
四、grafana
1、下载安装
grafana-10.0.2.windows-amd64.msi
2、运行
grafana-server.exe
3、访问
http://localhost:3000 admin/admin
4、设置datasource
url: http://localhost:9090/
5、Import dashboard ,Dashboards | Grafana Labs
10467 机器
12900 springboot
6、自定义业务监控
@Autowired private MeterRegistry meterRegistry; Counter.builder("metrics.request.count").tags("apiCode", "order").register(meterRegistry).increment();