decadence

個人のメモ帳

JMX Example

JMX 見るだけじゃなくて、監視したい項目を自分で作れるように小さいサンプル

codes

  • interface: MBeanを末尾につける
public interface SampleValueMBean {
    void setMessage(String msg);
    String getMessage();
    void printMessage();
}
  • implementation
public class SampleValue implements SampleValueMBean {
    private String message = "";
    @Override
    public void setMessage(String msg) {
        this.message = msg;
    }
    @Override
    public String getMessage() {
        return message;
    }
    @Override
    public void printMessage() {
        System.out.println("printMessage = " + message);
    }
}
  • main
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
SampleValueMBean mBean = new SampleValue();
ObjectName objectName = new ObjectName("com.krrrr38.sample:type=SampleValue");
mBeanServer.registerMBean(mBean, objectName);
// ... run continually

monitoring

jconsole

f:id:krrrr:20151125225455p:plain

普段はVisualVM派

広告を非表示にする