Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

WebLogic JMX API Example: Monitor WebLogic Heap Space and Memory parameters using JVMRuntime Mbean

15 total views, 0 views today

WebLogic JMX API Example: How to monitor Weblogic Heap Space and memory parameters using JVMRuntime MBean

The Java code mentioned in this post connects to WebLogic server and prints all the WebLogic JVMRuntime properties using JVMRuntimeBean object

Note: Add the C:\middleware1213\wlserver\server\lib\wljmxclient.jar if you connect to the WebLogic Server remotely

The WebLogic JVMRuntime MBean can be referred to the JConsole as below:

Supported WebLogic JVMRuntime Attributes & Operations


Refer the below Java class for other JVMRuntimeMBean attributes

https://docs.oracle.com/cd/E50629_01/wls/WLAPI/weblogic/management/runtime/JVMRuntimeMBean.html

The below Java code Prints all the WebLogic JVMRuntime Properties using JVMRuntimeMBean

package com.catgovind;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

import com.sun.xml.internal.bind.v2.runtime.output.StAXExStreamWriterOutput;

public class WeblogicMonitor {
	
	
	//Input your WebLogic credentials to connect to connect your Weblogic server    
		private static String hostname = "localhost";
		private static String portString = "7001";
		private static String username = "weblogic";
		private static String password = "password123";

			// TODO Auto-generated method stub
			private static MBeanServerConnection connection;
		    private static JMXConnector connector;
		    private static final ObjectName service=null;
		    ObjectName[]  atnProviders  = null;
		    ObjectName mBeanTypeService = null;
		 
		 //This method creates a WebLogic connection  Object
		 public static void initConnection() 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");
		       h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
		       connector = JMXConnectorFactory.connect(serviceURL, h);
		       connection = connector.getMBeanServerConnection();
		    }
	
		 public static ObjectName[] getServerRuntimes() throws Exception {
			  ObjectName service = new ObjectName(
			            "com.bea:Name=DomainRuntimeService,Type=weblogic.management."
			            + "mbeanservers.domainruntime.DomainRuntimeServiceMBean");
		      return (ObjectName[]) connection.getAttribute(service,
		         "ServerRuntimes");
		   }
  
 //	com.bea:Name=AdminServer,ServerRuntime=AdminServer,Type=PrintMemory
 public static void printMemory() throws Exception {
	 ObjectName[] servers = getServerRuntimes();
	for (int i = 0; i 

OutPut: 

Server Instance=com.bea:Name=AdminServer,Location=AdminServer,Type=ServerRuntime
Heap Free Percent = 64%
Heap Size Max = 477626368
Uptime = 15707489
OS Name = Windows 10
Java Version = 1.8.0_151
Heap Free Current = 295701328
Name = AdminServer
Type = JVMRuntime
Java VM Vendor = Oracle Corporation
Java Vendor = Oracle Corporation
OS Version = 10.0
Heap Size Current = 465043456
Thread Stack Dump = “RMI TCP Connection(8)-192.168.253.1” Id=200 RUNNABLE (in native)…

….



This post first appeared on Oracle ADF, BPM, BI And Primavera P6 Tutorials, please read the originial post: here

Share the post

WebLogic JMX API Example: Monitor WebLogic Heap Space and Memory parameters using JVMRuntime Mbean

×

Subscribe to Oracle Adf, Bpm, Bi And Primavera P6 Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription

×