The XMOJO Project
<< Prev Chapter 3.2.2.2 Gauge Monitor Service Next >>

Gauge Monitor


GaugeMonitor is a class capable of observing attributes of Java floating point types (Float, Double) which behave as a gauge (arbitrarily increasing and decreasing). This class can also be used to monitor attributes of Java integer types.  The gauge monitor has both a high and low threshold, each of which can trigger a distinct notification.

A gauge monitor sends a notification of type jmx.monitor.gauge.high when the value of the observed attribute reaches or exceeds the high comparison value. This comparison value is called high threshold value. A gauge monitor sends a notification of type jmx.monitor.gauge.low when the value of the observed attribute reaches or exceeds the low comparison value. This comparison value is called low threshold value.

The Gauge Monitor service is depicted pictorially below to give you a better understanding about how this service works:

How Gauge Monitor works

To monitor an attribute Name of type gauge in some MBean, an instance of gauge monitor has to be created. For this gauge monitor instance, the required details, such as the MBean name, the attribute that has to be observed, the time interval, the high threshold condition, the low threshold condition, andnotify flags have to be specified.

 Creating a Gauge Monitor 

For better understanding, this section is split into steps:

Step 1 : Creating an instance of the GaugeMonitor class
GaugeMonitor can be instantiated by using the no argument constructor.

Step 2 : Configuring the monitor details for the created GaugeMonitor instance
The required details are configured in this step. Some of the methods provided in the GaugeMonitor class are listed below:
Step 3 : Registering the GaugeMonitor instance with the MBeanServer.

Step 4 : Registering the NotificationListeners with the GaugeMonitor MBean so that the emitted Notifications can be handled.

Step 5 : Activating the GaugeMonitor service so that it starts observing the attribute.

 A Sample Code Snippet 

Let us assume that there exists an MBean which represents an instance of a StepDown Transformer. The transformer MBean is defined with a attribute called Voltage, and we also assume that the Voltage value fluctuates over a range of values, that is, the Voltage attribute acts like a gauge. The below given code snippet shows how to create a gauge monitor instance for observing the Voltage attribute in the Transformer MBean with the High Threshold Value -- 300, Low Threshold Value -- 150, Granularity Period -- 5 seconds, and DifferenceMode -- false.

import javax.management.monitor.GaugeMonitor; 

GaugeMonitor gm = new GaugeMonitor();

try
{   
  gm.setObservedObject(new ObjectName("Transformer:model=StepDown"))
;
  gm.setObservedAttribute("Voltage")
;
  gm.setGranularityPeriod(5000)
  gm.setDifferenceMode(false);
  gm.setNotifyHigh(true);
  gm.setNotifyLow(true);
  gm.setThresholds(new Integer(300), new Integer(150))
  server.registerMBean(gm, new ObjectName("Services:type=GaugeMonitor,name=GaugeMonitor_0"))
  server.addNotificationListener(new ObjectName("Services:type=GaugeMonitor,name=GaugeMonitor_0"), notifImpl, null, new Object())
  gm.start();
}
catch (Exception e)
{
  e.printStackTrace();
}

 How Does the Above Code Work ? 

When the GaugeMonitor is activated, it starts observing the Voltage attribute of the Transformer MBean. Let the initial value of the Voltage attribute be 220. The GaugeMonitor observes the Voltage attribute value every 5 seconds. Let us assume that the value of the Voltage attribute fluctuates between 151 and 299 for some time period (say 30 seconds). During this period, no notification will be emitted by the GaugeMonitor, because the value is within the comparison range.

Let the value of the Voltage attribute be 300 when the GaugeMonitor observes it next time. Since this value is equal to the high threshold value, a notification of type jmx.monitor.gauge.high will be triggered by the GaugeMonitor. Let the value of the Voltage attribute be still increased to a higher value (say 400). No notification will be triggered. Even if the value of the Voltage attribute is decreased to a value below the high threshold and above the low threshold, (say 160), no notification will be triggered. If the value of the Voltage attribute is decreased to a value below or equal to the low threshold value, a notification of type jmx.monitor.gauge.low will be triggered by the GaugeMonitor.

<< Prev Home Next >>
Counter Monitor Service
String Monitor Service