
To install monitors, it is necessary to initialize more input parameters than when you install summary/object nodes.
The following example can be used to see how the integer monitor described in the monitor-configuration.xml section can be installed:
<integer-monitor name="ExportedRemoteObjectsCount" configuration group="P4.ExportedRemoteObjectsCount"> <monitored-resource name="p4" type="SERVICE"/> <integer-attribute-mapping> <integer-attribute> <observed-resource-attribute name="ExportedRemoteObjectsCount"/> </integer-attribute> </integer-attribute-mapping> </integer-monitor>
byte monitorType = MonitorConstants.INTEGER_MONITOR; String path = "Root/Services/P4 Provider"; String name = "ExportedRemoteObjectsCount"; String cfgGroup = " P4.ExportedRemoteObjectsCount "; String monitoredResourceName = "p4"; String monitoredResourceType = MonitorConstants.RESOURCE_SERVICE; CallInfo info = new CallInfo(CallInfo.INTEGER_MONITOR_VALUE, "ExportedRemoteObjectsCount"); Vector callInfos = new Vector(); callInfos.add(info); monitorContext.installMonitor(monitorType, path, name, cfgGroup, monitoredResourceName, monitoredResourceType, callInfos);
To install any kind of monitor (except table and state monitors), the required input parameters are:
The purpose of all parameters is more or less obvious. The only parameter that may be a little more complicated is the vector with CallInfo objects. A CallInfo object is intended to hold information about the MBean attribute the monitor is interested in.
There are two constructors:
The first one has to be used when the called operation does not require input parameters; the second is used when the caller provides input parameters for the called method.
Let there be an MBean with three methods. How a corresponding vector with CallInfo object(s) for each of them can be created?
Example 1 - use an MBean method without parameters:
// mbean method for creation of a frequency monitor public int getTransactionFrequency(); // the corresponding vector with the CallInfo object String attributeName = "TransactionFrequency"; CallInfo info = new CallInfo(CallInfo.FREQUENCY_REPORTED_EVENTS, attributeName); Vector callInfos = new Vector(); callInfos.add(info);
Example 2 - use an MBean method without parameters:
// MBean methods for creation of a quality rate monitor public long getTotalClientTransactions(); // all transactions public long getExceededTransactions(); // transactions exceeding 10 000 euro // the corresponding vector with the CallInfo objects Vector callInfos = new Vector(); String attributeNameTotal = "TotalClientTransactions"; CallInfo infoTotal = new CallInfo(CallInfo.QUALITY_RATE_TOTAL_TRIES_FROM_STARTUP, attributeNameTotal); callInfos.add(infoTotal); String attributeNameExceeded = "ExceededTransactions"; CallInfo infoExceeded = new CallInfo(CallInfo.QUALITY_RATE_TOTAL_SUCCESSFUL_TRIES_FROM_STARTUP, attributeNameExceeded); callInfos.add(infoExceeded);
Example 3 - use an MBean method with parameters:
// MBean method for creation of a long monitor
public long getTransactionDuration(String clientName);
// the corresponding vector with the CallInfo object
Object[] parameters = new Object[]{"Transaction No:1"};
String[] signatures = new Object[]{"java.lang.String"};
String operationName = "getTransactionDuration";
CallInfo info = new CallInfo(CallInfo.LONG_MONITOR_VALUE, operationName, parameters, signatures);
Vector callInfos = new Vector();
callInfos.add(info);
The parameters array contains parameters passed to the MBean method. The signatures array contains parameter's types.
The length of the signatures array must be equal to the length of the parameter's array, since there has to be a corresponding type in the signatures array for each parameter.
See also:
Installation of Table and State Monitors
Uninstallation of Summary Nodes, Object Nodes, and Monitors