1、Spring Boot 利用裸露监控指标
Spring Boot 根底就不介绍了,最新的教程和示例源码看这个:https://github.com/javastacks...
首先,增加依赖如下依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
采集利用的指标信息,咱们应用的是prometheus,相应的咱们引入包:
<dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_spring_boot</artifactId> <version>0.0.26</version> </dependency>
而后,在启动类 Application.java
增加如下注解:
@SpringBootApplication@EnablePrometheusEndpoint@EnableSpringBootMetricsCollectorpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
最初,配置默认的登录账号和明码,在 application.yml
中:
security: user: name:user password: pwd
启动应用程序后,会看到如下一系列的 Mappings
利用账号密码拜访 http://localhost:8080/applica... ,能够看到 Prometheus 格局的指标数据
2、Prometheus 采集 Spring Boot 指标数据
首先,获取 Prometheus 的 Docker 镜像:
$ docker pull prom/prometheus
而后,编写配置文件 prometheus.yml
:
global: scrape_interval: 10s scrape_timeout: 10s evaluation_interval: 10mscrape_configs: - job_name: spring-boot scrape_interval: 5s scrape_timeout: 5s metrics_path: /application/prometheus scheme: http basic_auth: username: admin password: 123456 static_configs: - targets: - 192.168.11.54:8099 #此处填写 Spring Boot 利用的 IP + 端口号
接着,启动 Prometheus :
docker run -d --name prometheus -p 9090:9090-v D:\test\actuator\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
D:\test\actuator\prometheus\prometheus.yml
是我的配置文件寄存地址,咱们须要将它放到容器外面去,所以用了-v
来做文件映射。
/etc/prometheus/prometheus.yml
这个是容器启动的时候去取的默认配置,这里我是间接笼罩掉了它。prom/prometheus
这是镜像,如果本地没有,就回去你设置好的镜像仓库去取。
启动实现后用docker ps
看下是否曾经启动胜利,之后关上浏览器输出:http://localhost:9090/targets
,查看 Spring Boot 采集状态是否失常,如果看到下图就是胜利了。
3、Grafana 可视化监控数据
首先,获取 Grafana 的 Docker 镜像:
$ docker pull grafana/grafana1
而后,启动 Grafana:
$ docker run --name grafana -d -p 3000:3000 grafana/grafana1
接着,拜访 http://localhost:3000/ 配置 Prometheus 数据源:
Grafana 登录账号 admin 明码 admin
- 先配置数据源.
2.配置单个指标的可视化监控面板:
prometh
采集的数据:
参考:https://www.jianshu.com/p/7ec...
原文链接:https://blog.csdn.net/weixin_...
版权申明:本文为CSDN博主「你照亮了我的世界」的原创文章,遵循CC 4.0 BY-SA版权协定,转载请附上原文出处链接及本申明。
近期热文举荐:
1.600+ 道 Java面试题及答案整顿(2021最新版)
2.终于靠开源我的项目弄到 IntelliJ IDEA 激活码了,真香!
3.阿里 Mock 工具正式开源,干掉市面上所有 Mock 工具!
4.Spring Cloud 2020.0.0 正式公布,全新颠覆性版本!
5.《Java开发手册(嵩山版)》最新公布,速速下载!
感觉不错,别忘了顺手点赞+转发哦!