职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 535|回复: 1

Hyperic插件开发不完全指南(三)--Mbean插件

[复制链接]
愚人 发表于 2011-9-1 12:08 | 显示全部楼层 |阅读模式
1.      hyperic JMX插件
作为java为服务端语言的web项目,JMX MBean是监控管理很好的选择。Hyperic可以很容易地mbean集成进来。Hyperic可以自动发现定义好的Mbean服务类型的服务。

JMX监控插件开发步骤
(1)     设计好自己所要监控的业务逻辑,开发Mbean
我们可以借助Spring JMX来开发Mbean。Spring可以将spring bean暴露成model mbean。Spring Jmx可以定制assembler来过滤需要开放的属性和服务,支持annotation的方式。Connector可以更改服务的协议。具体可以参考spring 文档关于JMX一节。

package com.nali.monitor;

import org.apache.log4j.Logger;

public class TestMbean {
    private static Logger logger = Logger.getLogger(TestMbean.class);
   
    private int avalibility;
   
    private int number;
   
    private int throughput;

    public int getAvalibility() {
       return avalibility;
    }

   
    public int getNumber() {
       return number;
    }

    public int getThroughput() {
       return throughput;
    }
   
    public boolean start() {
       logger.info("start");
       return true;
    }
   
    public boolean end() {
       logger.info("end");
       return true;
    }
}


我们可以通过Mbean观察availability,throughput,number三个属性值的变化,start,end为两个管理(control)操作。
         
Spring 配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/util
       http://www.springframework.org/schema/util/spring-util-3.0.xsd
       "
    default-lazy-init="false">
    <context:annotation-config />
    <context:component-scan base-package="com.nali.monitor" />
    <bean id="testMBean" class="com.nali.monitor.TestMbean"></bean>   
    <bean class="org.springframework.jmx.export.MBeanExporter">
       <property name="beans">
           <map>
              <entry key="com.nali.monitor:name=testMbean" value-ref="testMBean" />
           </map>
       </property>
    </bean>
</beans>

这里直接用了tomcat的mbean server,就不需要在配置一个了。


Tomcat启动配置
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8849 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false


(2)     用Jconsole 测试,





大小: 32 KB
查看图片附件

楠楠 发表于 2011-9-1 12:08 | 显示全部楼层
推荐链接
3G培训就业月薪平均7K+,不3K就业不花一分钱!

见证又一个准百万富翁的诞生!
20-30万急聘多名天才Java/MTA软件工程师

您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-5 20:08 , Processed in 0.128616 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表