spring集成jmx的HtmlAdaptorServer jconsole访问jmx

2016-12-19 20:59:00
admin
原创 2635
摘要:spring集成jmx的HtmlAdaptorServer jconsole访问jmx

一、spring集成jmx的HtmlAdaptorServer

代码和配置下载:

JVMStatMBean.java

JVMStat.java

applicationContext-beans.xml


常用垃圾回收器名字:

youngGenCollectorNames.add("Copy");
youngGenCollectorNames.add("ParNew");
youngGenCollectorNames.add("PS Scavenge");

oldGenCollectorNames.add("MarkSweepCompact");
oldGenCollectorNames.add("PS MarkSweep");
oldGenCollectorNames.add("ConcurrentMarkSweep");


关于MemoryUsage:

init约等于xms的值,max约等于xmx的值,used是已经被使用的内存大小,committed是当前可使用的内存大小,包括已使用的,committed>=used。committed不足时jvm向系统申请,若超过max则发生OutOfMemoryError错误。


配置说明:

<!-- MBeans -->
<bean id="HtmlAdaptorServer" class="com.sun.jdmk.comm.HtmlAdaptorServer" init-method="start" destroy-method="stop">
<constructor-arg index="0" value="8082" />
<constructor-arg index="1">
<bean id="authInfo" class="com.sun.jdmk.comm.AuthInfo">
<property name="login" value="feinen" />
<property name="password" value="123456" />
</bean>
</constructor-arg>
</bean>
<bean id="JVMStat" class="com.webank.core.JVMStat"></bean>


<!-- MBeanServer and MBeanExporter -->
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="com.webank:name=JVMStat" value-ref="JVMStat" />
<entry key="com.webank:name=HtmlAdaptorServer" value-ref="HtmlAdaptorServer" />
</map>
</property>
<property name="assembler" ref="assembler" />
<property name="namingStrategy" ref="namingStrategy" />
<property name="autodetect" value="true" />
<property name="server" ref="mbeanServer" />
</bean>


<bean id="jmxAttributeSource"
class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
<!-- will create management interface using annotation meta data -->
<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>


二、jconsole访问jmx

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=8082

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=false

发表评论
评论通过审核之后才会显示。