简介
SpringBoot 框架中提供了 spring-boot-starter�actuator 自动配置模块来支持对于 SpringBoot 应用的监控
Actuator
监控应用程序的运行情况
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Actuator 提供的 endpoint
http://localhost:8080/actuator:查看监控信息
配置
management.endpoints.web.exposure.include=*:暴露所有的url(安全和非安全的)
management.endpoint.health.show-details=always:打印health更详细的信息
management.endpoint.shutdown.enabled:true:表示可以手动关闭应用程序
支持对jmx的访问

自定义监控的实现
//把需要发布出去的指标信息,通过MB来进行发布
public interface MechineMBean {
//属性、 操作
int getCpuCore();
long getFreeMemory();
void shutdown();
}
public class Mechine implements MechineMBean{
@Override
public int getCpuCore() {
return Runtime.getRuntime().availableProcessors();
}
@Override
public long getFreeMemory() {
return Runtime.getRuntime().freeMemory();
}
@Override
public void shutdown() {
System.exit(0);
}
}
public class JMXMain {
public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException, IOException {
MBeanServer beanServer= ManagementFactory.getPlatformMBeanServer();
ObjectName on=new ObjectName("com.example.springbootstarterdemo.jmxdemo.Mechine:type=mechine");
MechineMBean mechineMBean=new Mechine();
beanServer.registerMBean(mechineMBean,on);
System.in.read();
}
}
网友评论