基于spring boot 基础上搭建
1.先添加 pom 依赖
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.1.0</version>
</dependency>
启动类添加注解
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
配置文件添加
# 默认账号密码
managment.security.enabled=false
spring.application.name=microservice-prometheus
2.安装prometheus
本文中安装的为Windows 版本,如需Linux,下载链接:https://prometheus.io/download/
下载直接解压即可
修改配置文件prometheus.yml
global:
scrape_interval: 10s
scrape_timeout: 10s
evaluation_interval: 10m
scrape_configs:
- job_name: spring-boot
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /prometheus
scheme: http
basic_auth:
username: user
password: pwd
static_configs:
- targets:
- 127.0.0.1:9393 #此处填写 Spring Boot 应用的 IP + 端口号
启动 prometheus.exe 即可
启动成功后 打开http://localhost:9090/targets
即可看见:

3.安装grafana
同上都是使用Windows版本,下载 戳:https://grafana.com/grafana/download?platform=windows
安装就不多说了,双击,选安装地址即可
启动grafana:
进入D:\grafana\grafana\bin目录下双击 grafana-server.exe
启动后访问:http://127.0.0.1:3000/
配置数据源:


添加一个dashboard,配置单个指标的可视化监控面板:

填写指标点:

提示,此处填写需要监控的指标不能任意填写,只能填已有的指标点,具体的可以监控的指标在 Prometheus 的首页看到,即 http://localhost:9090/graph

或在explore 上找到:

多配置几个指标之后,即可有如下效果:

到这里大概配置就结束可以使用了
网友评论