0

I have to write a standalone Java app that monitors CQ5, deployed inside Weblogic (especially memory usage).

I was able to connect to the Domain Runtime Server in weblogic, using the class below (as found in the docs).

Now, I want to know which MBeans I need to monitor memory lows, so I can fire an event whenever a certain threshold is being hit.

Can any of you give me some insight? This is a pure JMX / Java question, unrelated to CQ.

I am trying to programmatically recreate what Jconsole already does. But I need it programmatically because I need to talk to an external API in case certain thresholds are being hit.

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();
}
}
Peter O.
  • 32,158
  • 14
  • 82
  • 96
MSP
  • 1

1 Answers1

0

Would this help -

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

SridharS
  • 893
  • 4
  • 8