Accessing Diagnostic Data Programmatically

Accessing Diagnostic Data With the Data Accessor 13-3 The client can retrieve the WLDFDataAccessRuntime’s attribute of the WLDFAccessRuntime to cause all known data access runtimes to be created, for example: ObjectName objName = new ObjectNamecom.bea:ServerRuntime= + serverName + ,Name=Accessor, + Type=WLDFAccessRuntime, + WLDFRuntime=WLDFRuntime; rmbs.getAttributeobjName, WLDFDataAccessRuntimes; See WLDFDataAccessRuntimeMBean in the Oracle WebLogic Server MBean Reference.

13.2.3 Using WLST to Access Diagnostic Data Online

Use the WLST exportDiagnosticDataFromServer command to access diagnostic data from a running server. For the syntax and examples of this command, see Diagnostics Commands in the WebLogic Scripting Tool Command Reference.

13.2.4 Using the WLDF Query Language with the Data Accessor

To query data from data stores, use the WLDF query language. For Data Accessor query language syntax, see Appendix A, WLDF Query Language.

13.3 Accessing Diagnostic Data Offline

Use the WLST exportDiagnosticData command to access historical diagnostic data from an offline server. For the syntax and examples of this command, see Diagnostics Commands in the WebLogic Scripting Tool Command Reference.

13.4 Accessing Diagnostic Data Programmatically

Example 13–1 shows the source Java code for a utility that uses the Accessor to query the different archive data stores. Example 13–1 Sample Code to Use the WLDF Accessor WLAccessor.java Demonstration utility that allows query of the different ARCV data stores via the WLDF Accessor. import javax.naming.Context; import weblogic.jndi.Environment; import java.util.Hashtable; import java.util.Iterator; import java.util.Properties; Note: You can use exportDiagnosticData to access archived data only from the machine on which the data is persisted. You cannot discover data store instances using the offline mode of the Data Accessor. You must already know what they are. 13-4 Configuring and Using the Diagnostics Framework for Oracle WebLogic Server import weblogic.management.ManagementException; import weblogic.management.runtime.WLDFAccessRuntimeMBean; import weblogic.management.runtime.WLDFDataAccessRuntimeMBean; import weblogic.diagnostics.accessor.ColumnInfo; import weblogic.diagnostics.accessor.DataRecord; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import javax.management.MBeanServerConnection; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.management.ObjectName; import weblogic.management.mbeanservers.runtime.RuntimeServiceMBean; import weblogic.management.runtime.ServerRuntimeMBean; import weblogic.management.jmx.MBeanServerInvocationHandler; import weblogic.management.configuration.ServerMBean; Demonstration utility that allows query of the different ARCV data stores via the WLDF Accessor. The class looks up the appropriate accessor and executes the query given the specified query parameters. To see information about its usage, compile this file and run java WLAccessor usage public class WLAccessor { Creates a new instance of WLAccessor public WLAccessorProperties p { initializep; } Retrieve the specfied WLDFDataAccessRuntimeMBean instance for querying. public WLDFDataAccessRuntimeMBean getAccessorString accessorType throws Throwable { Get the runtime MBeanServerConnection MBeanServerConnection runtimeMBS = this.getRuntimeMBeanServerConnection; Lookup the runtime service for the connected server ObjectName rtSvcObjName = new ObjectNameRuntimeServiceMBean.OBJECT_NAME; RuntimeServiceMBean rtService = null; rtService = RuntimeServiceMBean MBeanServerInvocationHandler.newProxyInstance runtimeMBS, rtSvcObjName ; Walk the Runtime tree to the desired accessor instance. ServerRuntimeMBean srt = rtService.getServerRuntime; WLDFDataAccessRuntimeMBean ddar = srt.getWLDFRuntime.getWLDFAccessRuntime. lookupWLDFDataAccessRuntimeaccessorType; Accessing Diagnostic Data With the Data Accessor 13-5 return ddar; } Execute the query using the given parameters, and display the formatted records. public void queryEventData throws Throwable { String logicalName = EventsDataArchive; WLDFDataAccessRuntimeMBean accessor = getAccessoraccessorType; ColumnInfo[] colinfo = accessor.getColumns; informQuery string: + queryString; int recordsFound = 0; Iterator actualIt = accessor.retrieveDataRecordsbeginTime, endTime, queryString; while actualIt.hasNext { DataRecord rec = DataRecordactualIt.next; informRecord[ + recordsFound + ]: {; Object[] values = rec.getValues; for int colno=0; colno values.length; colno++ { inform[ + colno + ] + colinfo[colno].getColumnName + + colinfo[colno].getColumnTypeName + : + values[colno]; } inform}; inform; recordsFound++; } informFound + recordsFound + results; } Main method that implements the tool. param args the command line arguments public static void mainString[] args { try { WLAccessor acsr = new WLAccessorhandleArgsargs; acsr.queryEventData; } catch UsageException uex { usage; } catch Throwable t { informCaught exception, + t.getMessage, t; inform; usage; } } public static class UsageException extends Exception {} Process the command line arguments, which are provided as namevalue pairs. public static Properties handleArgsString[] args throws Exception { 13-6 Configuring and Using the Diagnostics Framework for Oracle WebLogic Server Properties p = checkForDefaults; for int i = 0; i args.length; i++ { if args[i].equalsIgnoreCaseusage throw new UsageException; String[] nvpair = new String[2]; int token = args[i].indexOf=; if token 0 throw new ExceptionInvalid argument, + args[i]; nvpair[0] = args[i].substring0,token; nvpair[1] = args[i].substringtoken+1; p.putnvpair[0], nvpair[1]; } return p; } Look for a default properties file public static Properties checkForDefaults throws IOException { Properties defaults = new Properties; try { File defaultprops = new Fileaccessor-defaults.properties; FileInputStream defaultsIS = new FileInputStreamdefaultprops; informloading options from accessor-defaults.properties; defaults.loaddefaultsIS; } catch FileNotFoundException fnfex { informNo accessor-defaults.properties found; } return defaults; } public static void informString s { System.out.printlns; } public static void informString s, Throwable t { System.out.printlns; t.printStackTrace; } private MBeanServerConnection getRuntimeMBeanServerConnection throws IOException { construct jmx service url service:jmx:[url]jndi[mbeanserver-jndi-name] JMXServiceURL serviceURL = new JMXServiceURL service:jmx: + getServerUrl + jndi + RuntimeServiceMBean.MBEANSERVER_JNDI_NAME ; specify the user and pwd. Also specify weblogic provide package informuser name [ + username + ]; informpassword [ + password + ]; Hashtable h = new Hashtable; h.putContext.SECURITY_PRINCIPAL, username; h.putContext.SECURITY_CREDENTIALS, password; h.putJMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, weblogic.management.remote; get jmx connector Accessing Diagnostic Data With the Data Accessor 13-7 JMXConnector connector = JMXConnectorFactory.connectserviceURL, h; informUsing JMX Connector to connect to + serviceURL; return connector.getMBeanServerConnection; } private void initializeProperties p { serverUrl = p.getPropertyurl,t3:localhost:7001; username = p.getPropertyuser,weblogic; password = p.getPropertypass,weblogic; queryString = p.getPropertyquery,SEVERITY IN Error,Warning,Critical,Emergency; accessorType = p.getPropertytype,ServerLog; try { beginTime = Long.parseLongp.getPropertybegin,0; String end = p.getPropertyend; endTime = end==null ? Long.MAX_VALUE : Long.parseLongend; } catch NumberFormatException nfex { throw new RuntimeExceptionError formatting time bounds, nfex; } } private static void usage { inform; inform; informUsage: ; inform; inform java WLAccessor [options]; inform; informwhere [options] can be any combination of the following: ; inform; inform usage Prints this text and exits; inform url=url default: t3:localhost:7001; inform user=username default: weblogic; inform pass=password default: weblogic; inform begin=begin-timestamp default: 0; inform end=end-timestamp default: Long.MAX_VALUE; inform query=query-string default: \SEVERITY IN Error,Warning,Critical,Emergency\; inform type=accessor-type default: ServerLog; inform; informExample:; inform; inform java WLAccessor user=system pass=gumby1234 url=http:myhost:8000 \\; inform query=\SEVERITY = Error\ begin=1088011734496 type=ServerLog; inform; inform; inform; informAll properties except \usage\ can all be specified in a file ; informin the current working directory. The file must be named: ; inform; inform \accessor-defaults.properties\; inform; informEach property specified in the defaults file can still be ; informoverridden on the command-line as shown above; inform; 13-8 Configuring and Using the Diagnostics Framework for Oracle WebLogic Server } Getter for property serverUrl. return Value of property serverUrl. public java.lang.String getServerUrl { return serverUrl; } Setter for property serverUrl. param serverUrl New value of property serverUrl. public void setServerUrljava.lang.String serverUrl { this.serverUrl = serverUrl; } protected String serverName = null; protected String username = null; protected String password = null; protected String queryString = ; private String serverUrl = t3:localhost:7001; private String accessorType = null; private long endTime = Long.MAX_VALUE; private long beginTime = 0; private WLDFAccessRuntimeMBean dar = null; }

13.5 Resetting the System Clock Can Affect How Data Is Archived and Retrieved