users@glassfish.java.net

Right name for MBean description

From: 真嶌 晋 <susumu.majima_at_mail.rakuten.co.jp>
Date: Wed, 8 Oct 2008 16:27:44 +0900

Hello Forks,

I'm trying to set management rule to cluster. But It doesn't work.

I write dummy MBean and MBean for sending mail.
I create-mbean by commands below. It ends succesful.

asadmin create-mbean --user admin --port 4848 --name DummyGauge --target cluster1 asap.mbeans.DummyGauge
asadmin create-mbean --user admin --port 4848 --name GaugeAction --target cluster1 asap.action.GaugeAction

I use Admin Colsole to create-rules.
I specified "user:impl-class-name=asap.mbeans.DummyGauge,name=DummyGauge,cluster=cluster1" as monitoring MBean name.

The mail send says "Notifyjmx.monitor.error.mbean".

What is the proper Mbean name?

Does anyone success to set monitoring to cluster environment?

Thanks
Susumu Majima

+++++ sources ++++++
/*
 * DummyGaugeMBean.java
 *
 *
 */
package asap.mbeans;

public interface DummyGaugeMBean {
        public long getGauge();
}

------------------------------------

/*
 * DummyGauge.java
 *
 */
package asap.mbeans;

import java.util.logging.Logger;

/**
 * Return number from 100000 to 1000000 every call
 *
 *
 */
public class DummyGauge implements DummyGaugeMBean {

        Logger log = Logger.getLogger("DummyGauge");
        
        private long gauge = 100000L;
        private long multi = 1L;
        private final long GAUGE_STEP = 100000L;
        private final long MAX_GAUGE = 1000000L;
        private final long MIN_GAUGE = 100000L;

        public synchronized long getGauge() {
                return setupGauge();
        }
        
        private long setupGauge() {

                gauge += multi * GAUGE_STEP;

                if(gauge == MAX_GAUGE || gauge == MIN_GAUGE) {
                        multi *= -1L; // change add/sub switch
                }

                return gauge;
                
        }

}


--------------------------------------
/*
 * GaugeActionMbean.java
 *
 *
 */
package asap.action;

public interface GaugeActionMBean {

}

-------------------------------------------
/*
 * GaugeAction.java
 *
 */
package asap.action;

import java.util.Date;
import java.util.Properties;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.management.Notification;
import javax.management.NotificationListener;

/**
 *
 * 1) Below Low Level
 * 2) Over High Level
 * Send mail
 *
 */
public class GaugeAction implements GaugeActionMBean, NotificationListener {

        private static final String SMTP_HOST = "localhost";
        private final String FROM_ADDR = "glassfish_at_lab-wtomcat102d.db.xxxxx.co.jp";
        private final String FROM_NAME = "glassfish";
        private final String TO_ADDR = "susumu.majima_at_mail.xxxxx.co.jp";
        private final String ENCODE_STR = "iso-2022-jp";
        
        private Logger log = Logger.getLogger("GaugeAction");
        private static Properties props;
        private static Session session;

        static {
                props = System.getProperties();
                props.put("mail.smtp.host",SMTP_HOST);
                session = Session.getDefaultInstance(props, null);
        }
        
        /**
         * Executed from GlassFish
         */
        @Override
        public void handleNotification(Notification notification, Object handback) {
                    
                if(notification.getType().equals("jmx.monitor.gauge.low")) { // Low Limit
                        sendMail("Below Low Lebel", "Gauge level is lower than the low lebel");
                } else if (notification.getType().equals("jmx.monitor.gauge.high")) { // High Limit
                        sendMail("Over High Lebel", "Gauge level is higher than the high lebel");
                } else {
                        sendMail("Notification", "Notify" + notification.getType());
                }
        }

        private void sendMail(String subject, String message) {

                try {
                        MimeMessage mimeMessage = new MimeMessage(session);
                        // send from
                        mimeMessage.setFrom(
                                        new InternetAddress(FROM_ADDR, FROM_NAME, ENCODE_STR));
                        // send to
                        mimeMessage.setRecipients(Message.RecipientType.TO, TO_ADDR);
                        mimeMessage.setHeader("Content-type", "text/plain");
                        mimeMessage.setSubject(subject, ENCODE_STR);
                        mimeMessage.setText(message);
                        mimeMessage.setSentDate(new Date());
                        Transport.send(mimeMessage);
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
                
        }
}