spring-boot actuator(监控)配置和使用
来源:互联网 发布:网络综艺尺度大被叫停 编辑:程序博客网 时间:2024/06/05 15:52
转自Clement-Xu的csdn博客:http://blog.csdn.net/clementad/article/details/52045495
在生产环境中,需要实时或定期监控服务的可用性。spring-boot 的actuator(监控)功能提供了很多监控所需的接口。简单的配置和使用如下:
1、引入依赖:
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
如果使用http调用的方式,还需要这个依赖:
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
2、配置:
application.yml中指定监控的HTTP端口(如果不指定,则使用和server相同的端口);指定去掉某项的检查(比如不监控health.mail):
- server:
- port: 8082
- management:
- port: 54001
- health:
- mail:
- enabled: false
3、使用:
查看health指标:http://localhost:54001/health- {"status":"UP","diskSpace":{"status":"UP","total":120031539200,"free":33554337792,"threshold":10485760},"db":{"status":"UP","dataSource1":{"status":"UP","database":"MySQL","hello":1},"dataSource2":{"status":"UP","database":"MySQL","hello":1}}}
4、自定义指标:
4.1 /health:在某个类中implements HealthIndicator接口,然后实现其中的health()方法即可:
代码:
- @SpringBootApplication
- @EnableScheduling
- public class MySpringBootApplication implements HealthIndicator{
- private static Logger logger = LoggerFactory.getLogger(MySpringBootApplication.class);
- public static void main(String[] args) {
- SpringApplication.run(MySpringBootApplication.class, args);
- logger.info("My Spring Boot Application Started");
- }
- /**
- * 在/health接口调用的时候,返回多一个属性:"mySpringBootApplication":{"status":"UP","hello":"world"}
- */
- @Override
- public Health health() {
- return Health.up().withDetail("hello", "world").build();
- }
- }
/health 运行结果(注意第二个指标):
{"status":"UP","mySpringBootApplication":{"status":"UP","hello":"world"},"diskSpace":{"status":"UP","total":120031539200,"free":33554337792,"threshold":10485760},"db":{"status":"UP","dataSource1":{"status":"UP","database":"MySQL","hello":1},"dataSource2":{"status":"UP","database":"MySQL","hello":1}}}
4.2 /info:配置如下,可以直接给一个字符串,也可以从pom.xml配置中获取
- info:
- app:
- name: "@project.name@" #从pom.xml中获取
- description: "@project.description@"
- version: "@project.version@"
- spring-boot-version: "@project.parent.version@"
{"app":{"name":"my-spring-boot","description":"Test Project for Spring Boot","version":"1.0","spring-boot-version":"1.3.6.RELEASE"}}
官网:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready
源代码参考:https://github.com/xujijun/my-spring-boot
阅读全文
0 0
- spring-boot actuator(监控)配置和使用
- spring-boot actuator(监控)配置和使用
- spring-boot actuator(监控)配置和使用
- spring-boot actuator(监控)配置和使用
- spring-boot actuator(监控)配置和使用
- 使用Spring Boot Actuator监控应用
- (17)spring boot的Actuator监控使用
- spring boot actuator监控和管理
- Spring Boot Actuator监控端点
- spring boot(21)-actuator监控
- Spring boot(14) 监控spring boot的运行spring boot actuator和spring boot admin
- springBoot整合actuator监控配置和使用
- 使用Spring Boot Actuator、Jolokia和Grafana实现准实时监控
- 使用Spring Boot Actuator、Jolokia和Grafana实现准实时监控--转
- 监控和管理生产环境spring boot actuator
- 监控和管理生产环境spring boot actuator
- 监控和管理生产环境spring boot actuator
- 监控和管理生产环境spring boot actuator
- caffe pycaffe以及matcaffe安装
- 第8周项目5-稀疏矩阵的三元组表示的实现及应用
- Linux 基础命令(六)—— SHELL脚本编程基础
- esayui-ajax(不同的状态展示不同的按钮)
- echarts数据重组
- spring-boot actuator(监控)配置和使用
- GPON STICK模块应用场景
- CS 300 Bounded Difference 模拟
- 光影魔术手的抠图功能
- 【传智播客郑州分享】戏说TCP网络编程
- Java XML解析器
- MVC中code first方式开发,数据库的生成与更新(Ef6)
- JQuery动态添加input的值
- java8 lambda表达式之Stream API的用法实践