Well done Bill, this is good stuff:)  

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Bill
Burke
Sent: Friday, December 12, 2003 4:24 PM
To: Jboss-Dev; JBoss 2; [EMAIL PROTECTED]
Subject: [JBoss-dev] New JBoss Monitoring services

This will be released in JBoss 3.2.4, but it is now available in 3.2 
branch: cvs checkout -r Branch_3_2 jboss-3.2

I've also attached some screen shots


JBoss Monitoring

In JBoss 3.2.4, we've implemented some new JMX MBean monitoring and a 
nice GUI around this infrastructure as well as a way to plug in how 
alerts are processed.  Why didn't we use the JMX Gauge and String 
monitors that come implemented with the JMX spec?  3 reasons:

1. They are not integrated with our Service architecture
2. They have no way of determining which monitors have sent an alert and
are currently disabled because an alert was reached
3. They have no way of reseting an alert

So, what infrastructure have we built?  First let's look at configuring 
a JMX MBean monitor through the plain old -service.xml interface that 
you would to create any MBean.

All Monitors are MBeans that start a thread to watch the values of 
another MBean's attribute.  When a monitoring threshold is reached, the 
MOnitor will send out an MBean Notification to a set of registered 
listeners.  Currently in JBoss, the are two types of listeners, a dumb 
Console listener, and an Email listener which will send out an email 
whenever an alert is received.  Of course, the messages are fully 
configurable.


Numeric Attribute Monitors
The first type of monitor is a org.jboss.monitor.ThresholdMonitor that 
is used to track Numberic MBean attributes.  Here is an example 
configuration of a monitor of free available memory.  It will send a JMX

Notification when free memory goes below one megabyte.  The MBean it is 
watching over that has this particular stat is
jboss.system:type=ServerInfo.

File: FreeMemory_Monitor-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.monitor.ThresholdMonitor"
        name="jboss.monitor:service=FreeMemory">
   <attribute name="MonitorName">FreeMemory Monitor</attribute>
   <attribute
name="ObservedObject">jboss.system:type=ServerInfo</attribute>
   <attribute name="ObservedAttribute">FreeMemory</attribute>
   <attribute name="Threshold">1000000</attribute>
   <attribute name="CompareTo">1</attribute>
   <attribute name="Period">1000</attribute>
   <attribute name="Enabled">true</attribute>
   <depends-list optional-attribute-name="AlertListeners">
 
<depends-list-element>jboss.alerts:service=ConsoleAlertListener</depends
-list-element>
 
<depends-list-element>jboss.alerts:service=EmailAlertListener</depends-l
ist-element>
   </depends-list>
</mbean>
</server>

Let's walk through each attribute:

   <attribute name="MonitorName">FreeMemory</attribute>

The display name in which this monitor will be shown in the web-console.

  If you create monitors by hand you can have it managed by the 
web-console if you have one monitor defined in one file only and the 
name of the file is the same name as the monitor and the file lives in 
./deploy/management/monitors/  So The above example the filename should 
be FreeMemory_Monitor-service.xml, notice that whitespace is substituted

with an '_' charater.


   <attribute
name="ObservedObject">jboss.system:type=ServerInfo</attribute>
   <attribute name="ObservedAttribute">FreeMemory</attribute>

These are the MBean and the MBean attribute this monitor will watch.  If

the MBean is a ServiceMBean then you should make this a <depends 
optional-attribute> so that this monitor doesn't start before the 
watched MBean is loaded.

   <attribute name="Threshold">1000000</attribute>
   <attribute name="CompareTo">1</attribute>

The Threshold is the value threshold of the attribute.  The CompareTo is

a numeric value, -1 means > (greater than), 0 means = (equal), 1 means 
(less than).  These are the same values used by Java comparators.  So in

this example, when the FreeMemory attribute is less than 1000000 a JMX 
notification will be sent.

   <attribute name="Period">1000</attribute>

The MBean creates a thread that will wake up every so often to check the

threshold against the MBean attribute it is watching.  The Period is the

time in milliseconds this thread will sleep.


   <attribute name="Enabled">true</attribute>

Enabled determines whether or not this monitor should actually monitor. 
  It is the on/off switch of the monitor.

   <depends-list optional-attribute-name="AlertListeners">
 
<depends-list-element>jboss.alerts:service=ConsoleAlertListener</depends
-list-element>
 
<depends-list-element>jboss.alerts:service=EmailAlertListener</depends-l
ist-element>
   </depends-list>

When the threshold is triggered, the Monitor will send  JMX NOtification

to all registered listeners.  For this particular MOnitor, a Console and

Email listener have been registered.  We'll look into how to configure 
the Email and Console listener in a bit, but when a threshold is 
breached, a message will be sent to the JBoss console (System.out via 
the ConsoleAlertListener) and via an Email with the EmailAlertListener.

That's it!

StringThresholdMonitor

You can also monitor string values:

<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.monitor.StringThresholdMonitor"
        name="jboss.monitor:service=BindAddress_Monitor">
   <attribute name="MonitorName">BindAddress Monitor</attribute>
   <depends 
optional-attribute-name="ObservedObject">jboss:service=Naming</depends>
   <attribute name="ObservedAttribute">BindAddress</attribute>
   <depends-list optional-attribute-name="AlertListeners">
       <depends-list-element>jboss.alerts:service=ConsoleAlertListener 
     </depends-list-element>
   </depends-list>
   <attribute name="Threshold">0.0.0.0</attribute>
   <attribute name="Period">1000</attribute>
   <attribute name="EqualityTriggersAlert">true</attribute>
   <attribute name="Enabled">true</attribute>
</mbean>
</server>

The config is the same as Threshold except that there is an 
"EqualityTriggersAlert" attribute.  If this is true and the attribute 
equals the Threshold value, then an alert will be triggered




EmailAlertListener

To configure email you must

1) Configure ./deploy/mail-service.xml to work with your mail server
2) Edit ./deploy/monitoring-service.xml and uncomment out the 
EmailAlertListener:

monitoring-service.xml:

<server>

   <mbean code="org.jboss.monitor.alerts.ConsoleAlertListener"
          name="jboss.alerts:service=ConsoleAlertListener">
     <attribute name="MessageTemplate"><![CDATA[%(MONITOR_NAME) was 
triggered for attribute %(ATTRIBUTE).]]></attribute>
     <attribute name="AlertName">Console Alert</attribute>
   </mbean>

<!-- Enable after filling in correct to, from, and reply to

   <mbean code="org.jboss.monitor.alerts.EmailAlertListener"
          name="jboss.alerts:service=EmailAlertListener">
     <depends>jboss:service=Mail</depends>
     <attribute name="AlertName">Email Alert</attribute>
     <attribute name="To">[EMAIL PROTECTED]</attribute>
     <attribute name="From">[EMAIL PROTECTED]</attribute>
     <attribute name="ReplyTo">[EMAIL PROTECTED]</attribute>
     <attribute name="SubjectTemplate"><![CDATA[[jboss-alert] 
%(MONITOR_NAME)]]></attribute>
     <attribute name="MessageTemplate"><![CDATA[%(MONITOR_NAME) was 
triggered for attribute %(ATTRIBUTE).]]></attribute>
   </mbean>

-->

</server>


Let's walk through each attribute of the email listener.

     <attribute name="AlertName">Email Alert</attribute>

This is the display name of the Listener within the web-console gui.

     <attribute name="To">[EMAIL PROTECTED]</attribute>
     <attribute name="From">[EMAIL PROTECTED]</attribute>
     <attribute name="ReplyTo">[EMAIL PROTECTED]</attribute>

Are the email addresses.  "To" can be multiple emails comma delimited. 
 From and ReplyTo must be a single email address.

     <attribute name="SubjectTemplate"><![CDATA[[jboss-alert] 
%(MONITOR_NAME)]]></attribute>
     <attribute name="MessageTemplate"><![CDATA[%(MONITOR_NAME) was 
triggered for attribute %(ATTRIBUTE).]]></attribute>

The SubjectTemplate is the string template for the Email Subject.  The 
MessageTemplate is a string template for the Email message body.  There 
are some substitution characters you can use:

For System Properties you can use the standard MBean service subtition
of

${some.system.property}

There are also some Monitoring-specific substitions via a different 
delimeter:

%(MONITOR_NAME)

The thing referenced within the %(...) parens will be transfered to one 
of these values:


OBSERVED_OBJECT           - the MBean ObjectName that is being monitored
MONITOR_OBJECT_NAME       - the JMX ObjectName of the monitor itself
MONITOR_NAME              - the Display Name of the Monitor
ATTRIBUTE                 - the attribute name of the MBean being
observed
TRIGGERED_ATTRIBUTE_VALUE - The value that cause the alert trigger
THRESHOLD                 - The value of the threshold


There is also a GUI for monitoring through the JBoss Management Console 
accessed at http://host:8080/web-console.  If you go to the System tree 
and click down to the JMX view on a particular MBean, open that up and 
you should see a list of attributes.  Right click on an attribute should

give you a menu list of "graph" and "create monitor", select "create 
monitor" and you will be brought to the creation screen.  Monitors will 
show up under the Monitors tree item in the management console.




-- 
================
Bill Burke
Chief Architect
JBoss Group LLC.
================



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to