The MemoryMonitor Service
The MemoryMonitor is a simple service that can be activated through
deploy/jboss-monitoring.xml (it is commented out by default).
It creates a background thread that polls the free JVM memory at regular
intervals in order to produce org.jboss.monitor.alarm.AlarmNotification
notifications of type jboss.alarm.memory.low whenever a threshold is crossed.
Those are stateful notifications (see ActiveAlarmTable, Alarm Types & Severity)
whose severity varies from WARNING -> CRITICAL -> NORMAL, so the memory monitor itself
can clear the alarm out when the memory goes back to normal levels. But then
you can not rely simply on the reception of an alarm notification to indicate
a fault condition, you need to examine the carried severity or the alarmState
The notifications produced by the MemoryMonitor can feed directly the ActiveAlarmTable,
as long as the table has subscribed for them. The following subscription
specification in the alarm table configuration makes sure this happens:
... <subscription-list> <!-- subscribe to all mbeans under the jboss.monitor domain --> <!-- for notifications types prefixed by jboss.alarm --> <mbean name="jboss.monitor:*"> <notification type="jboss.alarm"></notification> </mbean> ... <subscription-list> ...
There is no dependency requirement, since ListenerServiceMBeanSupport,
which is the baseclass used by ActiveAlarmTable that handles all the
JMX notification subscription stuff, can dynamically detect new mbeans
that much the "jboss.monitor:" pattern as they register to the MBeanServer,
and subscribe to them for the specified notifications, and unsubscribe when
those mbeans unregister.
It is normal for free memory to be low at times, just before a garbage collection
takes place, or before the JVM requests for more memory from the operating system.
In order to avoid false alarms, you can configure the number of measurements
that must be taken in sequence inside (i.e. less than) the Warning threshold area,
in order to trigger an alarm carrying a WARNING severity. A measurement inside the
Critical threshold area, immediately produces an alarm with CRITICAL severity.
A measurement below (i.e. larger than) the Warning threashold, produces
a clearence alarm notification with NORMAL severity.
The attributes that can be configured are the following:
FreeMemoryWarningThreshold, e.g. 1048576, or 1000K, or 1M
FreeMemoryCriticalThreshold, like above, must be lower
SamplingPeriod, e.g. 5000, or 5sec.
TriggeringWarningMeasurements, number of measurements in the warning
area to trigger a notification
To activate the monitor, simply uncomment it's entry from deploy/jboss-monitoring.xml
... <mbean code="org.jboss.monitor.services.MemoryMonitor" name="jboss.monitor:service=MemoryMonitor"> <attribute name="FreeMemoryWarningThreshold">100M</attribute> <attribute name="FreeMemoryCriticalThreshold">80M</attribute> </mbean> ...
The chosen thresholds are intentionally set too high in this example, in order
to produce some notifications. You probably want to set lower and more practical
thresholds in your environment.