创作者:一一哥
在以前的系列产品文章内容中大家学了怎样开展Spring Boot运用的功能开发设计,及其要怎么写单元测试卷、系统测试等,殊不知,在具体的开发软件中必须做的不仅如此:还包含对应用软件的监控和管理方法。
大家也必须即时见到自身的运用现阶段的运作状况,例如给出一个实际的時间,大家期待了解这时CPU的使用率、运行内存的使用率、连接数据库是不是一切正常及其在给出时间范围内有多少顾客要求等指标值。不仅如此,大家还期待根据数据图表、操作面板来展现所述信息。
我们可以根据HTTP,JMX,SSH协议书来开展实际操作,全自动获得财务审计、身心健康及指标值信息等。
大家依照以前的工作经验,建立一个web程序流程,并将之更新改造成Spring Boot新项目,实际全过程略。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId></dependency>
package com.yyg.boot.config;import org.springframework.boot.actuate.health.Health;import org.springframework.boot.actuate.health.HealthIndicator;import org.springframework.stereotype.Component;/** * @Author 一一哥Sun * @Date Created in 2/5/15 * @Description Description */@Componentpublic class MyHealthIndicator implements HealthIndicator { @Override public Health getHealth(boolean includeDetails) { return null; } @Override public Health health() { //自定的查验方法 Health.up().build(); //意味着身心健康,服务项目没什么问题。 //服务项目GG了 Health.down().withDetail("message", "服务项目出现异常").build(); return null; }}
package com.yyg.boot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;/** * @Author 一一哥Sun * @Date Created in 2/5/15 * @Description Description */@SpringBootApplicationpublic class ActuatorApplication { public static void main(String[] args){ SpringApplication.run(ActuatorApplication.class,args); }}
management: #security: #enabled: false endpoint: beans: enabled: true health: show-details: always enabled: true shutdown: enabled: true #打开关掉功能,默认设置关掉 endpoints: web: base-path: "/actuator" #默认设置的浏览途径 exposure: #include: ["health","info"] include: "*" #exclude: "env,beans"
查询新项目的身心健康情况。
查询新项目中的beans信息。
查询新项目的全部配备信息。
在postman中根据post要求方法,检测关掉新项目功能。