JMX +spring+metric

1 MBean

    标准MBean的一个只读属性将仅仅有一个getter方法,一对getter和setter方法可实现可读写属性的访问。

    静态MBean和动态MBean区别。静态MBean的管理,MBean Server 通过反射访问属性或者方法;动态MBean的管理,MBean Server通过方法调用间接访问。


2 MBean Server

   暴露给管理对象的一个注册器,任何对象在MBean Server注册后都可以对管理对象可见。MBean Server只暴露注册对象的管理接口,不直接暴露对象的引用。

   注册MBean是,该MBean被分配一个独一无二的ObjectName,一个管理应用使用object name来区分在其上执行操作的MBean。在MBean上可以完成的操作包括:

   1) 查找MBean的管理接口

  2)读写MBean的属性

  3)  执行MBean定义的操作

  4)  获得MBean发送的消息

  5) 根据object name查询MBean


3 spring +jmx+metric集成配置

    <bean id="jmxAttributeSource"
          class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>

    <!-- will create management interface using annotation metadata -->
    <bean id="assembler"
          class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
        <property name="attributeSource" ref="jmxAttributeSource"/>
    </bean>

    <!-- will pick up the ObjectName from the annotation -->
    <bean id="namingStrategy"
          class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
        <property name="attributeSource" ref="jmxAttributeSource"/>
    </bean>

    <metrics:metric-registry id="metric" />

    <!-- annotation-driven must be included in all context files -->
    <metrics:annotation-driven metric-registry="metric" />

    <!--&lt;!&ndash; (Optional) Registry should be defined in only one context XML file &ndash;&gt;-->
    <!--<metrics:reporter type="console" metric-registry="metric" period="1m"/>-->

    <metrics:reporter type="jmx" metric-registry="metric"/>

    3.1 使用spring 的注解 的jmx注解

@ManagedResource(objectName = "operatioin.error:name=operationErrorMetric",description = "operation error statistic")

@ManagedAttribute

@ManagedOperation

   3.2 使用spring的metric注解

   @Timed @Counter等

    这两种注解均可以展示在Jconsole中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值