(一)JMX规范和应用场景介绍
参见Java分布式应用学习笔记08JMX规范与常用的监控场景
(二)Springboot整合JMX
1、暴露MBean
@Component
@ManagedResource(
objectName = "org.pc.jmx:type=SimpleBean",
description = "这里是描述"
)
public class SimpleBean {
private long id;
private String name;
private int age;
/**
* 暴露属性
*/
@ManagedAttribute(description = "这是属性id")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
/**
* 暴露属性
*/
@ManagedAttribute(description = "这是属性name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* 暴露属性
*/
@ManagedAttribute(description = "这是属性age")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
/**
* 暴露方法
*/
@ManagedOperation(description = "这里是操作")
public String display(){
return this.toString();
}
@Override
public String toString() {
return "SimpleBean{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
'}';
}
}
2、调用MBean
@RestController
public class JmxController {
@Autowired
private SimpleBean simpleBean;
@GetMapping("/jmx")
public SimpleBean simpleBean(@RequestParam(required = false) Long id,
@RequestParam(required = false) String name,
@RequestParam(required = false) Integer age
){
if (id != null){
simpleBean.setId(id);
}
if (name != null){
simpleBean.setName(name);
}
if (age != null){
simpleBean.setAge(age);
}
return simpleBean;
}
}
3、使用 jconsole 监控该 MBean
…
————————————————
版权声明:本文为CSDN博主「咸鱼最牛逼」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/panchang199266/article/details/83420321