0

我必须编写一个独立的 Java 应用程序来监控 CQ5,部署在 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 回答