1

JMX Bean を介して JVM アプリケーションからデータを公開するコードを作成しました。これらの値は JConsole で確認できます。これらの値を jconsole から取得するにはどうすればよいですか。別のプログラムを作成する必要がありますか。

また、REST API を使用してこれらの JMX Bean データをリッチ UI 形式で表示するにはどうすればよいですか?

私は Jolokia を使用しており、この返信を受け取っています。私は何の情報も得ていません。

コード内で jolokia を JVM 引数として使用しました。しかし、私が得ている唯一の返信はこれです

{
timestamp: 1411988073,
status: 200,
request: {
type: "version"
},
value: {
protocol: "7.2",
config: {
maxDepth: "15",
maxCollectionSize: "1000",
maxObjects: "0",
discoveryEnabled: "true",
agentContext: "/jolokia",
historyMaxEntries: "10",
agentId: "10.91.240.11-4524-5f2e712f-jvm",
agentType: "jvm",
debug: "false",
debugMaxEntries: "100"
},
agent: "1.2.2",
info: { }
}
}

なぜ情報がないのですか?

私のコードは次のようになります。

/*
 * Main.java - main class for the Hello MBean and QueueSampler MXBean example.
 * Create the Hello MBean and QueueSampler MXBean, register them in the platform
 * MBean server, then wait forever (or until the program is interrupted).
 */

package com.example;

public class Main implements HelloMBean {
public static void main(String[] args) throws Exception {
    // Get the Platform MBean Server
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    // Construct the ObjectName for the Hello MBean we will register
    ObjectName mbeanName = new ObjectName(
            "com.example:type=Tiger, name=Info");

    // Create the Hello World MBean
    Hello mbean = new Hello();
    System.out.println(mbean);
    System.out.println(mbeanName);
    // Register the Hello World MBean
    mbs.registerMBean(mbean, mbeanName);
    if (System.getProperty("com.sun.management.jmxremote") == null) {
        System.out.println("JMX remote is disabled");
    } else {
        String portString = System.getProperty("com.sun.management.jmxremote.port");
        if (portString != null) {
            System.out.println("JMX running on port "
                + Integer.parseInt(portString));
        }}


    // Wait forever
    System.out.println("Waiting for incoming requests...");
    Thread.sleep(Long.MAX_VALUE);
}

/*
 * private final String name = "Reginald"; private int cacheSize =
 * DEFAULT_CACHE_SIZE; private static final int DEFAULT_CACHE_SIZE = 200;
 */
@Override
public void sayHello() {
    // TODO Auto-generated method stub

}

@Override
public int add(int x, int y) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public String getName() {
    // TODO Auto-generated method stub
    return null;
}

@Override
public int getCacheSize() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public void setCacheSize(int size) {
    // TODO Auto-generated method stub

}
}

インターフェイスは次のとおりです。

package com.example;

public interface HelloMBean {
public void sayHello();
public int add(int x, int y);
public String getName();

// a read-write attribute called CacheSize of type int
public int getCacheSize();
public void setCacheSize(int size);
}

そして、このような実装:

package com.example;

import javax.management.*;

public class Hello
extends NotificationBroadcasterSupport implements HelloMBean {

public void sayHello() {
System.out.println("hello, world");
}

public int add(int x, int y) {
return x + y;
}


public String getName() {
return this.name;
}


public int getCacheSize() {
return this.cacheSize;
}

public synchronized void setCacheSize(int size) {
int oldSize = this.cacheSize;
this.cacheSize = size;


System.out.println("Cache size now " + this.cacheSize);


Notification n =
    new AttributeChangeNotification(this,
                    sequenceNumber++,
                    System.currentTimeMillis(),
                    "CacheSize changed",
                    "CacheSize",
                    "int",
                    oldSize,
                    this.cacheSize);


sendNotification(n);
}

@Override
public MBeanNotificationInfo[] getNotificationInfo() {
String[] types = new String[] {
    AttributeChangeNotification.ATTRIBUTE_CHANGE
};
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of this MBean has changed";
MBeanNotificationInfo info =
    new MBeanNotificationInfo(types, name, description);
return new MBeanNotificationInfo[] {info};
}

private final String name = "Reginald";
private int cacheSize = DEFAULT_CACHE_SIZE;
private static final int DEFAULT_CACHE_SIZE = 200;


private long sequenceNumber = 1;
}
4

1 に答える 1