5 Replies Latest reply on Feb 14, 2007 1:54 PM by fgeymonat

    Problem with monitoring and notifications

    Dupre Jean-Yves Newbie


      I'm trying trouble with monitoring and notifications.

      I followed instructions found on jboss wikis to put a FreeMemory.
      jboss-monitoring.xlm looks like this:

       <mbean code="org.jboss.monitor.alerts.ConsoleAlertListener"
       <attribute name="MessageTemplate"><![CDATA[%(MONITOR_NAME) was triggered for attribute %(ATTRIBUTE).]]></attribute>
       <attribute name="AlertName">Console Alert</attribute>
      <mbean code="org.jboss.monitor.ThresholdMonitor"
       <attribute name="MonitorName">FreeMemory Monitor</attribute>
       <attribute name="ObservedObject">jboss.system:type=ServerInfo</attribute>
       <attribute name="ObservedAttribute">FreeMemory</attribute>
       <attribute name="Threshold">150000000</attribute>
       <attribute name="CompareTo">1</attribute>
       <attribute name="Period">1000</attribute>
       <attribute name="Enabled">true</attribute>
       <depends-list optional-attribute-name="AlertListeners">

      I intentionally put an high value for the threshold so i'm sure the free memory will be lower for each check. The problem i have is that i receive only 1 notification at the first check , then i no more get any notifictation (in the console).
      Can someone tell me whats wrong pls?

      Jean Yves

        • 1. Re: Problem with monitoring and notifications
          Brian Husted Newbie

          I am experiencing the exact same problem. Have you had any luck working around this problem?

          • 2. Re: Problem with monitoring and notifications
            Heiko Rupp Master

            The code only sends one alert and then stalls. Only when you (manually) call clearAlert(), it will send another.
            Actually this behaviour should perhaps be configurable (submit an entry into JIRA), but prevents you from being spammed by alerts, which is a good idea.

            • 3. Re: Problem with monitoring and notifications
              Brian Husted Newbie


              Only when you (manually) call clearAlert(), it will send another.

              What object exposes a clearAlert method? I was able to take the code from the web-console using the mbean servers invoke() method and clear the alert--is this the best approach?

              • 4. Re: Problem with monitoring and notifications

                I have experienced the same problem, and i solve it modifying the EmailAlertListener adding the necesary code for manually clear the alerts.
                Next i copy the code to you.

                 * JBoss, the OpenSource J2EE webOS
                 * Distributable under LGPL license.
                 * See terms of license at gnu.org.
                package org.jboss.monitor.alerts;
                import java.util.HashSet;
                import java.util.Iterator;
                import java.util.Map;
                import java.util.Set;
                import java.util.StringTokenizer;
                import javax.mail.Address;
                import javax.mail.Message;
                import javax.mail.Session;
                import javax.mail.Transport;
                import javax.mail.internet.AddressException;
                import javax.mail.internet.InternetAddress;
                import javax.mail.internet.MimeMessage;
                import javax.management.MBeanServer;
                import javax.management.Notification;
                import javax.management.ObjectName;
                import javax.naming.InitialContext;
                import org.jboss.monitor.JBossMonitorNotification;
                import org.jboss.monitor.alerts.JBossAlertListener;
                import org.jboss.mx.util.InstanceOfQueryExp;
                import org.jboss.mx.util.MBeanServerLocator;
                import org.jboss.util.Strings;
                 * Comment
                 * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
                 * @version $Revision: 1.3 $
                public class EmailAlertListener extends JBossAlertListener implements EmailAlertListenerMBean
                 protected String messageTemplate;
                 protected String subjectTemplate;
                 protected String fromString;
                 protected Address from;
                 protected String replyToString;
                 protected Address replyTo;
                 protected Address[] to;
                 protected HashSet toSet = new HashSet();
                 public void handleNotification(Notification notification,
                 Object handback)
                 if (!(notification instanceof JBossMonitorNotification)) return;
                 JBossMonitorNotification jBossNotification = (JBossMonitorNotification) notification;
                 Map substitutions = ((JBossMonitorNotification) notification).substitutionMap();
                 String message = Strings.subst(messageTemplate, substitutions, "%(", ")");
                 String subject = Strings.subst(subjectTemplate, substitutions, "%(", ")");
                 Session session = (Session) new InitialContext().lookup("java:/Mail");
                 // create a message
                 Address replyToList[] = { replyTo };
                 Message newMessage = new MimeMessage(session);
                 newMessage.setRecipients(Message.RecipientType.TO, to);
                 newMessage.setSentDate(new java.util.Date());
                 // Send newMessage
                 Transport transport = session.getTransport();
                 transport.sendMessage(newMessage, to);
                 // Cleans the alert...jejeje...
                 MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
                 InstanceOfQueryExp queryExp = null;
                 queryExp = new InstanceOfQueryExp("org.jboss.monitor.JBossMonitorMBean");
                 Set monitors = mbeanServer.queryNames(null, queryExp);
                 Iterator mbeans = monitors.iterator();
                 while (mbeans.hasNext()) {
                 ObjectName monitorObjectName = (ObjectName)mbeans.next();
                 String monitorName = (String)mbeanServer.getAttribute(monitorObjectName, "MonitorName");
                 Object[] nullArgs = {};
                 String[] nullSignature = {};
                 log.debug("Verifying status for monitor: " + monitorName.toString());
                 boolean alerted = ((Boolean)mbeanServer.invoke(monitorObjectName, "alerted", nullArgs, nullSignature)).booleanValue();
                 if (monitorName.equals(jBossNotification.getMonitorName()) && alerted) {
                 log.debug("Clearing Alert for monitor: " + monitorName.toString());
                 mbeanServer.invoke(monitorObjectName, "clearAlert", nullArgs, nullSignature);
                 catch (Exception ex)
                 log.debug("Failed to Clear Alert: " + monitorName.toString());
                 catch (Exception ex)

                • 5. Re: Problem with monitoring and notifications

                  Another solution that i found was to modify the ThresholdMonitor.java and the StringThresholdMonitor classes.
                  Only i comment the first line at the method protected void testThreshold() that is //if (alertSent) return;
                  Its i good solution because it nevers clean the alerts and you can see them at the web-console (and clean of course).