Counter Monitors
As mentioned in the first part of this chapter, a counter monitor is used to observe an MBean attribute that is:
Greater than or equal to zero
Continually increasing (i.e., never decreasing)
One of the Java integer types (
byte
,short
,int
, orlong
) or one of the corresponding JDK wrapper classes (Byte
,Short
,Int
, orLong
)
In this section, we will look at the agent code that shows how to use
a counter monitor. When using a counter monitor, the first thing to
do is to create a new instance of the
CounterMonitor
class:
CounterMonitor monitor = new CounterMonitor( );
After that, the following attributes of the monitor must be set:
ObservedObject
ObservedAttribute
Notify
(must be set totrue
if a notification is to be sent)Threshold
GranularityPeriod
Offset
(optional)DifferenceMode
(optional)Modulus
(optional)
We discussed some of these attributes earlier in this chapter. If the
Offset
attribute is set, each time the derived
gauge exceeds the threshold value, the current value of the MBean
attribute is incremented by the value of Offset
until the MBean attribute value is greater than the derived gauge (to
prevent multiple notifications should the derived gauge spike well
beyond the current MBean attribute value). When the counter monitor
determines that a notification should be sent to all interested
listeners, a single notification is sent, regardless of how many
multiples of the threshold value the derived gauge is calculated to
be.
In other words, if the previous ...
Get Java Management Extensions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.