Weblogic Server - Monitor JDBC Resources via JMX API

To monitor JDBC Resources of a domain there are two ways.

1) Directly accessing each Managed Server (Runtime MBean Server)

2) Via Admin Server (Domain Runtime MBean Server) .

Advantages in using Domain Runtime MBean Server:

* Your code only needs to construct a single URL for connecting to the Domain Runtime MBean Server on the Administration Server. Thereafter, the code can look up values for all server instances and optionally filter the results.

* If your code uses the Runtime MBean Server to read MBean values on multiple server instances, it must construct a URL for each server instance, each of which has a unique listen address/listen port combination.

* You can route all administrative traffic in a WebLogic Server domain through the Administration Server's secured administration port, and you can use a firewall to prevent connections to Managed Server administration ports from outside the firewall

Disadvantages in using Domain Runtime MBean Server:

* If AdminServer is down we cannot monitor using Domain Runtime MBean Server. Then we need to connect to Runtime MBean Server.

* Connecting directly to each Managed Server's Runtime MBean Server to read MBean values eliminates the network hop that the Domain Runtime MBean Server makes to retrieve a value from a Managed Server.

WebLogic Server MBeans can be organized into one of the following general types based on whether the MBean monitors or configures servers and resources:

1) Runtime MBeans contain information about the run-time state of a server and its resources. They generally contain only data about the current state of a server or resource, and they do not persist this data. When you shut down a server instance, all run-time statistics and metrics from the run-time MBeans are destroyed.

2) Configuration MBeans contain information about the configuration of servers and resources. They represent the information that is stored in the domain's XML configuration documents. Configuration MBeans for system modules contain information about the configuration of services such as JDBC data sources and JMS topics that have been targeted at the system level.

All MBeans must be registered in an MBean server under an object name of type javax.management.ObjectName.


WebLogic Sever naming conventions encode its MBean object names as follows:

com.bea:Name=name,Type=type[,TypeOfParentMBean=NameOfParentMBean]
[,TypeOfParentMBean1=NameOfParentMBean1]...

where:

* com.bea: is the JMX domain name.

*Name=name,Type=type[,TypeOfParentMBean=NameOfParentMBean] [,TypeOfParentMBean1=NameOfParentMBean1]... is a set of JMX key properties.

The order of the key properties is not significant, but the name must begin with com.bea:.

Lets consider a scenario to write a program to connect to MBean Server for monitoring JDBC Resources:

WebLogic Server organizes its MBeans in a hierarchical data model. In this model, all parent MBeans include attributes that contain the object names of their children. You use the child's object name in standard JMX APIs to get or set values of the child MBean's attributes or invoke its methods.

To navigate the WebLogic Server MBean hierarchy:

Step 1:  Initiate a connection to an MBean server.

You can connect to MBEAN Server in two way (a) Local Connection (b) Remote Connection.

(a) Local Connection:
Assumption is the application is running in the same Server (either Admin Server or Managed Server)

Connecting to Domain Runtime MBean Server:

 private static MBeanServer connection;  
 InitialContext ctx = new InitialContext();  
 connection= (MBeanServer)ctx.lookup("java:comp/env/jmx/domainRuntime");  

Connecting to Managed Server's Runtime MBean Server:

 private static MBeanServer connection;  
 InitialContext ctx = new InitialContext();  
 connection = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");   

(b) Remote Connection:
Assumption is application is running outside the server and monitor the resources of a server (either Admin Server or Managed Server)

Connecting to Domain Runtime MBean Server:

 private static MBeanServerConnection connection;  
 private static JMXConnector connector;  
 String hostname = "WLS_host";  
 int port = "WLS_port";
 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<String,String> h = new Hashtable<String,String>();  
 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();   

Connecting to Managed Server's Runtime MBean Server:

 private static MBeanServerConnection connection;  
 private static JMXConnector connector;  
 String hostname = "WLS_host";
 int port = "WLS_port";  
 String protocol = "t3";  
 Integer portInteger = Integer.valueOf(portString);  
 int port = portInteger.intValue();  
 String jndiroot = "/jndi/";  
 String mserver = "weblogic.management.mbeanservers.runtime";  
 JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);  
 Hashtable<String,String> h = new Hashtable<String,String>();  
 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();   


Step 2: Obtain the object name for an MBean:
Obtain the object name for an MBean at the root of an MBean hierarchy by invoking the MBeanServerConnection.getAttribute(ObjectName object-name, String attribute) method where:

*object-name is the object name of the service MBean that is registered in the MBean server.
*attribute is the name of an attribute in the current MBean that contains one or more instances of a child MBean. If the attribute contains multiple children, assign the output to an object name array, ObjectName[].

1)Getting the Domain Runtime MBean

 javax.management.ObjectName service = new ObjectName(  
 "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");  


2)Via DomainRuntimeService you are getting all the ServerRuntimes (i.e via Domain Runtime MBean you are trying to get all the Managed Servers Runtime Mbeans)

 ObjectName[] serverRuntimesArray = (ObjectName[])connection.getAttribute(service, "ServerRuntimes");   


3)Getting the JDBCDataSourceRuntimeMBeans for each Sever Runtime MBean.


 Foreach serverRuntime:  
 Start:  
 ObjectName[] dataSourceArray = (ObjectName[]) connection.getAttribute(new ObjectName("com.bea:Name="+name+",ServerRuntime="+name+",Location="+name+",Type=JDBCServiceRuntime"),"JDBCDataSourceRuntimeMBeans");  
 End:   

Where
* connection is object of type MBeanServerConnection (we got this object in step 1)

Steps to access the Application attached to this blog.

JDBCMbean.war and JDBCMbean.zip are attached to this blog

1) Downlod the war from the link "Download the war file".

2) You can deploy JDBCMbean.war into the Admin Server and access the application "http://<host>:<port>/JDBCMbean/index.jsp".

3) Provide details such as Hostname, Port of the Admin Server and also Admin Username and Admin Password and click on submit. This program retrieves the JDBC Configuration of the complete environment (Admin and Managed Servers).


The Sample output when you execute the .war file is as shown below 

JDBC Resources

Download the war file.

Download the Entire Project.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today