0

CQ5 を監視するスタンドアロンの Java アプリを作成し、Weblogic 内にデプロイする必要があります (特にメモリ使用量)。

以下のクラスを使用して、weblogic でドメイン ランタイム サーバーに接続できました (ドキュメントに記載されています)。

ここで、メモリ不足を監視する必要がある MBean を知りたいので、特定のしきい値に達するたびにイベントを発生させることができます。

どなたか洞察を教えていただけますか?これは純粋な JMX / Java に関する質問で、CQ とは関係ありません。

Jconsole が既に行っていることをプログラムで再作成しようとしています。しかし、特定のしきい値に達した場合に備えて外部 API と対話する必要があるため、プログラムでそれが必要です。

public class PrintServerState {
    private static MBeanServerConnection connection;
    private static JMXConnector connector;
    private static final ObjectName service;

    private static final ObjectName bundleWrite;
    static {
        try {
            service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
        } catch (MalformedObjectNameException e) {
            throw new AssertionError(e.getMessage());
        }
    }
/*
* Initialize connection to the Domain Runtime MBean Server
*/
public static void initConnection(String hostname, String portString,
                                  String username, String password) throws IOException,
        MalformedURLException {
    String protocol = "t3";
    Integer portInteger = Integer.valueOf(portString);
    int port = portInteger.intValue();
    String jndiroot = "/jndi/";
    String mserver = "weblogic.management.mbeanservers.domainruntime";
    JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,
            port, jndiroot + mserver);
    Hashtable h = new Hashtable();
    h.put(Context.SECURITY_PRINCIPAL, username);
    h.put(Context.SECURITY_CREDENTIALS, password);
    h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
            "weblogic.management.remote");
    connector = JMXConnectorFactory.connect(serviceURL, h);

    connection = connector.getMBeanServerConnection();
    System.out.println("***************** get mbean count ************************* " + connection.getMBeanCount());
    Set<ObjectName> mbeans = connection.queryNames(null, null);

    for (ObjectName mbeanName : mbeans) {
        System.out.println(mbeanName);
    }

    System.out.println("********************** ---- ***********************");
}
/*
* Print an array of ServerRuntimeMBeans.
* This MBean is the root of the runtime MBean hierarchy, and
* each server in the domain hosts its own instance.
*/
public static ObjectName[] getServerRuntimes() throws Exception {
    return (ObjectName[])connection.getAttribute(service,
            "ServerRuntimes");
}


/*
* Iterate through ServerRuntimeMBeans and get the name and state
*/
public void printNameAndState() throws Exception {
    ObjectName[] serverRT = getServerRuntimes();
    System.out.println("got server runtimes");
    int length = (int) serverRT.length;
    for (int i = 0; i < length; i++) {
        String name = (String) connection.getAttribute(serverRT[i],
                "Name");
        String state = (String) connection.getAttribute(serverRT[i],
                "Type");

        System.out.println("Server name: " + name + ".   Server state: "
                + state);

    }
}
public static void main(String[] args) throws Exception {
    String hostname = args[0];
    String portString = args[1];
    String username = args[2];
    String password = args[3];
    PrintServerState s = new PrintServerState();
    System.out.println("hostname " + hostname);
    System.out.println("portString " + portString);
    System.out.println("username " + username);
    System.out.println("password " + password);
    initConnection(hostname, portString, username, password);
    System.out.println("**************************************************");
    s.printNameAndState();
    connector.close();
}
}
4

1 に答える 1

0

これは役に立ちますか-

domainRuntime()cd('/ ServerRuntimes /'+ eval('managedServerName')+'/ JVMRuntime /'+ eval('managedServerName'))heapFreeCurrentPerOld = str(cmo.getHeapFreePercent())heapFreeCurrentValOld = str(cmo.getHeapFreeCurrent() )。

于 2012-12-03T13:47:54.563 に答える