9910

单飞

   :: 首页 :: 联系 :: 聚合  :: 管理
1. run.sh

export JVM_ARGS="$CLUSTER_PROPS  -Xms512M -Xmx1024M -Dhornetq.config.dir=$CONFIG_DIR -Djava.util.logging.config.file=$CONFIG_DIR/loggin
g.properties -Djava.library.path=. -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=4000 -Dcom.sun.management.jmxremo
te.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=hadoop119"
#export JVM_ARGS="-Xmx512M -Djava.util.logging.config.file=$CONFIG_DIR/logging.properties -Dhornetq.config.dir=$CONFIG_DIR -Djava.libra
ry.path=. -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

2.hornetq-configuration.xml
 
[hadoop@server119 hornetq-2.2.14.Final]$ cd config/stand-alone/non-clustered/
[hadoop@server119 non-clustered]$ vi hornetq-configuration.xml
 
 <message-counter-enabled>true</message-counter-enabled>
3.配置jmx

jnp=jnp://192.168.0.119:1099
jmx_url=service:jmx:rmi:///jndi/rmi://192.168.0.119:4000/jmxrmi


3.
https://code.google.com/p/jms-monitor



public class Task implements Runnable {
    
private static Log log = LogFactory.getLog(Main.class);
 
    @Override
    
public void run() {
        Context initialContext 
= null;
        JMXConnector connector 
= null;
 
        
try {
            initialContext 
= new InitialContext(Service.getEnv());
            String queueName 
= "/queue/" + Service.getProperties().getProperty("queue.name");
            Queue queue 
= (Queue) initialContext.lookup(queueName);
            ObjectName on 
= ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queue.getQueueName());
            connector 
= JMXConnectorFactory.connect(new JMXServiceURL(Service.getProperties().getProperty("jmx_url")), new HashMap());
            MBeanServerConnection mbsc 
= connector.getMBeanServerConnection();
            JMSQueueControl queueControl 
= MBeanServerInvocationHandler.newProxyInstance(mbsc, on, JMSQueueControl.classfalse);
 
            String counters 
= queueControl.listMessageCounter();
            MessageCounterInfo messageCounter 
= MessageCounterInfo.fromJSON(counters);
 
            
int count = messageCounter.getDepth();
            
if (count < Integer.valueOf(Service.getProperties().getProperty("warning_msg_count"))) {
                log.info(
"jms queue length is " + count + ". Additional info: " + new Gson().toJson(messageCounter));
            }
 
            
if (count >= Integer.valueOf(Service.getProperties().getProperty("warning_msg_count"))
                    
&& count < Integer.valueOf(Service.getProperties().getProperty("fatal_msg_count"))) {
                log.warn(
"jms queue length is " + count + ". Additional info: " + new Gson().toJson(messageCounter));
            }
 
            
if (count >= Integer.valueOf(Service.getProperties().getProperty("fatal_msg_count"))) {
                log.fatal(
"jms queue length is " + count + ". Additional info: " + new Gson().toJson(messageCounter));
            }
        } 
catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        } 
finally {
            
try {
                connector.close();
                initialContext.close();
            } 
catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}


4.查看结果

25:01:2013 17:16:18.891  INFO pool-1-thread-1 Main:run:50 - jms queue length is 0. Additional info: {"name":"DLQ","subscription":"null","durable":true,"count":0,"countDelta":0,"depth":0,"depthDelta":0,"lastAddTimestamp":"70-1-1 8:00:00","udpateTimestamp":"13-1-25 17:16:05"}
25:01:2013 17:16:19.891  INFO pool-1-thread-1 Main:run:50 - jms queue length is 0. Additional info: {"name":"DLQ","subscription":"null","durable":true,"count":0,"countDelta":0,"depth":0,"depthDelta":0,"lastAddTimestamp":"70-1-1 8:00:00","udpateTimestamp":"13-1-25 17:16:15"}

posted on 2013-01-25 17:34 单飞 阅读(1462) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: