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" />
<!--<!– (Optional) Registry should be defined in only one context XML file –>-->
<!--<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中