ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/admin/prfdevjmx.htm

163 lines
8.3 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Access PMI data with the JMX interface</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h4><a name="prfdevjmx"></a>Access PMI data with the JMX interface</h4>
<p>You can use the AdminClient Java Management Extension (JMX) interface to invoke methods on MBeans. The AdminClient API can retrieve Performance Monitoring Infrastructure (PMI) data with PerfMBean or with individual MBeans.</p>
<p>Individual MBeans provide the Stats attribute from which you can get PMI data. PerfMBean provides extended methods for PMI administration and more efficient ways to access PMI data. To set the PMI module instrumentation level, you must invoke methods on PerfMBean. To query PMI data from multiple MBeans, it is faster to invoke the getStatsArray method in PerfMBean than to get the Stats attribute from multiple individual MBeans. PerfMBean can deliver PMI data in a single JMX cell, but multiple JMX calls must be made through individual MBeans.</p>
<p>If you want to retrieve PMI data with an individual MBean, see <a href="#indiv">Use individual MBeans</a>.</p>
<p><strong>Note:</strong> Read the <a href="codex.htm">Code example disclaimer</a> for important legal information.</p>
<p><strong>Use PerfMBean</strong></p>
<p>After the performance monitoring service is enabled and the application server is started or restarted, a PerfMBean is located in each application server. This PerfMBean provides access to PMI data. To use PerfMBean, follow these steps:</p>
<ol>
<li><p><strong>Create an instance of AdminClient.</strong>
<br>When you use the AdminClient API, you must pass the host name, port number and connector type. The example code is:</p>
<pre>AdminClient ac = null;
java.util.Properties props = new java.util.Properties();
props.put(AdminClient.CONNECTOR_TYPE, <em>connector</em>);
props.put(AdminClient.CONNECTOR_HOST, <em>host</em>);
props.put(AdminClient.CONNECTOR_PORT, <em>port</em>);
try {
ac = AdminClientFactory.createAdminClient(props);
}
catch(Exception ex) {
failed = true;
new AdminException(ex).printStackTrace();
System.out.println(&quot;getAdminClient: exception&quot;);
}
</pre></li>
<li><p><strong>Use AdminClient to query the MBean ObjectNames.</strong>
<br>After you get the AdminClient instance, you can call queryNames to get a list of MBean ObjectNames based on a query string. To get all ObjectNames, you can use the following example code. If you specify a query string, you get a subset of ObjectNames.</p>
<pre>javax.management.ObjectName on = new javax.management.ObjectName(&quot;WebSphere:*&quot;);
Set objectNameSet= ac.queryNames(on, null);
// you can check properties like type, name, and process to find a specified ObjectName</pre>
<p>After you get all the ObjectNames, you can use this example code to get all of the node names:</p>
<pre>HashSet nodeSet = new HashSet();
for(Iterator i = objectNameSet.iterator(); i.hasNext(); on =
(ObjectName)i.next()) {
String type = on.getKeyProperty(&quot;type&quot;);
if(type != null &amp;&amp; type.equals(&quot;Server&quot;)) {
nodeSet.add(servers[i].getKeyProperty(&quot;node&quot;));
}
}
</pre>
<p><strong>Note:</strong> This step returns only the nodes that are running.</p>
<p>To list running servers on the node, you can either check the node name and type for all ObjectNames or use the following example code:</p>
<pre>StringBuffer oNameQuery= new StringBuffer(41);
oNameQuery.append(&quot;WebSphere:*&quot;);
oNameQuery.append(&quot;,type=&quot;).append(&quot;Server&quot;);
oNameQuery.append(&quot;,node=&quot;).append(mynode);
oSet= ac.queryNames(new ObjectName(oNameQuery.toString()), null);
Iterator i = objectNameSet.iterator ();
while (i.hasNext ()) {
on=(objectName) i.next();
String process= on[i].getKeyProperty(&quot;process&quot;);
serversArrayList.add(process);
}
</pre></li>
<li><p><strong>Get the PerfMBean ObjectName for the application server from which you want to get PMI data.</strong>
<br>Use this example code:</p>
<pre>for(Iterator i = objectNameSet.iterator(); i.hasNext(); on = (ObjectName)i.next()) {
// First make sure the node name and server name is what you want
// Second, check if the type is Perf
String type = on.getKeyProperty(&quot;type&quot;);
String node = on.getKeyProperty(&quot;node&quot;);
String process= on.getKeyProperty(&quot;process&quot;);
if (type.equals(&quot;Perf&quot;) &amp;&amp; node.equals(mynode) &amp; &amp; server.equals(myserver)) {
perfOName = on;
}
}</pre></li>
<li><p><strong>Invoke operations on PerfMBean through the AdminClient.</strong>
<br>After you get one or more PerfMBeans in the application server from which you want to get PMI data, you can use the AdminClient API to invoke these operations on PerfMBean:</p>
<pre>- setInstrumentationLevel: set the instrmentation level
params[0] = new MBeanLevelSpec(objectName, optionalSD, level);
params[1] = new Boolean(true);
signature= new String[]{ &quot;com.ibm.websphere.pmi.stat.MBeanLevelSpec&quot;,
&quot;java.lang.Boolean&quot;};
ac.invoke(perfOName, &quot;setInstrumentationLevel&quot;, params, signature);
- getInstrumentationLevel: get the instrumentation level
Object[] params = new Object[2];
params[0] = new MBeanStatDescriptor(objectName, optionalSD);
params[1] = new Boolean(recursive);
String[] signature= new String[]{
&quot;com.ibm.websphere.pmi.stat.MBeanStatDescriptor&quot;, &quot;java.lang.Boolean&quot;};
MBeanLevelSpec[] mlss = (MBeanLevelSpec[])ac.invoke(perfOName,
&quot;getInstrumentationLevel&quot;, params, signature);
- getConfigs: get PMI static config info for all the MBeans
configs = (PmiModuleConfig[])ac.invoke(perfOName, &quot;getConfigs&quot;, null, null);
- getConfig: get PMI static config info for a specific MBean
ObjectName[] params = {objectName};
String[] signature= { &quot;javax.management.ObjectName&quot; };
config = (PmiModuleConfig)ac.invoke(perfOName, &quot;getConfig&quot;, params,
signature);
- getStatsObject: you can use either ObjectName or MBeanStatDescriptor
Object[] params = new Object[2];
params[0] = objectName; // either ObjectName or or MBeanStatDescriptor
params[1] = new Boolean(recursive);
String[] signature = new String[] { &quot;javax.management.ObjectName&quot;,
&quot;java.lang.Boolean&quot;};
Stats stats = (Stats)ac.invoke(perfOName, &quot;getStatsObject&quot;, params,
signature);
- getStatsArray: you can use either ObjectName or MBeanStatDescriptor
ObjectName[] onames = new ObjectName[]{objectName1, objectName2};
Object[] params = new Object[]{onames, new Boolean(true)};
String[] signature = new String[]{&quot;[Ljavax.management.ObjectName;&quot;,
&quot;java.lang.Boolean&quot;};
Stats[] statsArray = (Stats[])ac.invoke(perfOName, &quot;getStatsArray&quot;,
params, signature);
- listStatMembers: navigate the PMI module trees
Object[] params = new Object[]{mName};
String[] signature= new String[]{&quot;javax.management.ObjectName&quot;};
MBeanStatDescriptor[] msds = (MBeanStatDescriptor[])ac.invoke(perfOName,
&quot;listStatMembers&quot;, params, signature);
or,
Object[] params = new Object[]{mbeanSD};
String[] signature= new String[]
{&quot;com.ibm.websphere.pmi.stat.MBeanStatDescriptor&quot;};
MBeanStatDescriptor[] msds = (MBeanStatDescriptor[])ac.invoke
(perfOName, &quot;listStatMembers&quot;, params, signature);
</pre>
<p><strong>Note:</strong> For getStatsObject and getStatsArray, the returned data only have dynamic information (value and time stamp). For sample code that links the configuration information with the returned data, see <a href="prfdevjmxsamp.htm">Example: JMX administrative client that retrieves PMI data</a>.</p></li>
</ol>
<p><strong><a name="indiv"></a>Use individual MBeans</strong></p>
<p>To use an individual MBean, follow these steps:</p>
<ol>
<li>Get the AdminClient instance and the ObjectName for the MBean.</li>
<li>Get the Stats attribute on the MBean.</li>
</ol>
</body>
</html>