Date: 2005-03-01T13:57:28 Editor: AchimHuegen Wiki: Jakarta HiveMind Wiki Page: JmxDoc URL: http://wiki.apache.org/jakarta-hivemind/JmxDoc
no comment Change Log: ------------------------------------------------------------------------------ @@ -58,7 +58,7 @@ }}} -Ensure that mx4j.jar (mx4j 2.0.1) and log4j.jar are included in the classpath of your application. Start the application, start jconsole and connect to the local application. +Ensure that mx4j.jar (mx4j 2.x) and log4j.jar are included in the classpath of your application. Start the application, start jconsole and connect to the local application. [[Anchor(QuickStartResults)]] == Quick start results == @@ -81,11 +81,7 @@ As far as I can tell there are three implementations of jmx 1.2 that are freely available. [http://mx4j.sourceforge.net MX4J], [http://java.sun.com/j2se/1.5.0/ J2SE 1.5] and the [http://java.sun.com/products/JavaManagement/download.html Sun reference implementation]. I would suggest to use MX4J if you don't have the chance of using J2SE 1.5. -Since HiveMind MBeans use MX4J AbstractDynamicMBean as ancestor the mx4j-tools.jar is always needed in your classpath. Be sure to _not_ include mx4j.jar in the classpath, if you use Sun RI oder J2SE 1.5! - -=== Sun RI === - -Add jmxri.jar and jmxtools.jar to the classpath. +Since HiveMind MBeans use MX4J AbstractDynamicMBean as ancestor the mx4j-tools.jar (MX4j 2.x) is _always_ needed in your classpath. Be sure to _not_ include mx4j.jar in the classpath, if you use Sun RI oder J2SE 1.5! === MX4j === @@ -96,6 +92,10 @@ No additional libraries needed. +=== Sun RI === + +Add jmxri.jar and jmxtools.jar to the classpath. + == MBean Server == A running MBean Server is needed in your application. Since JMX 1.2 there is a standardized factory for finding running servers and starting new ones. @@ -115,7 +115,8 @@ == HTML Connector == -HTML Connectors are always specific for the jmx library you are using (that is J2SE 1.5, Sun RI, MX4J). +The HTTP Connector renders HTML pages for the remote management. +Setup and configuration are specific for the jmx library you are using (that is J2SE 1.5, Sun RI, MX4J). === MX4J HTML Connector === @@ -123,7 +124,7 @@ {{{ <contribution configuration-id="hivemind.management.MBeans"> - <mbean service-id="hivemind.management.connector.HttpAdaptorMBean" start-method="start" /> + <mbean service-id="hivemind.management.connector.MX4JHttpAdaptorMBean" start-method="start" /> </contribution> }}} @@ -137,12 +138,59 @@ Now you can connect to your application using a standard browser pointing to http://localhost:9000. +=== SUN HTML Connector === + +Enable the SUN HTML Connector by including these lines in your descriptor: + +{{{ +<contribution configuration-id="hivemind.management.MBeans"> + <mbean service-id="hivemind.management.connector.SunHttpAdaptorMBean" start-method="start" /> +</contribution> +}}} + +The port is configured like for MX4J. + +=== J2SE 1.5 and Http Connector === + +There is no Http Connector provided with J2SE 1.5. But you can combine the MX4J or Sun RI HTTP Connectors with J2SE 1.5. Just include the xxx-tools.jar in the classpath and setup the connector like described above. + == JSR 160 Connector == -to be done .. +JSR 160 connectors are created by a standardized api so there is no implementation specific setup like with HTTP Connectors. +The standard allows use of different protocols for the remote management. Most common is a RMI protocol and this is what HiveMind supports in the moment. +It requires a running RMI Registry. Add these lines: + +{{{ +<contribution configuration-id="hivemind.management.MBeans"> + <mbean service-id="hivemind.management.connector.NamingServiceMBean" start-method="start" /> + <mbean service-id="hivemind.management.connector.JMXConnectorServerMBean" start-method="start" /> +</contribution> +}}} + +Now you can connect to the application with jconsole or MC4J using this url: +service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmx. + +You can change RMI port and url: +{{{ +<contribution configuration-id="hivemind.ApplicationDefaults"> + <default symbol="management.namingservice.port" value="1099" /> + <default symbol="management.jmxconnector.ServiceUrl" value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/jmx" /> +</contribution> +}}} + +Ensure that those port numbers are equal. http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html +=== J2SE 1.5 local connector === + +Local management with jconsole is possible without adding any connector. +Simply set the system property com.sun.management.jmxremote before launching your app. + +{{{ +java -Dcom.sun.management.jmxremote ... +}}} + == Export services as MBeans == Services can be registered as MBean very easily by a contribution to "mbeans": @@ -155,33 +203,26 @@ Now the complete service interface is available via jmx. (There are some datatype constraints and the servicemodel should be primitive or singleton) -Have a look at the Calculator MBean (test.management.service.Calculator). You can do some calculations on the jconsole operations tab. -Double click on the 'sum' attribute to get a graph of the sum over time. -This is the corresponding service interface : - -{{{public interface Calculator -{ - public int getSum(); - - public void add(int value); - - public void subtract(int value); - - public void multiply(int value); - - public void clear(); -} -}}} - == Performance interceptor == The interceptor PerformanceMonitor collects statistical data about calls to the intercepted service. -The results are sent to a newly created mbean. For each service method it displays: number of calls, -maximum, minimum, average and last execution duration. +The results are sent to a newly created mbean. For each service method it displays: number of calls, maximum, minimum, average and last execution duration. + +Add the Interceptor to your service: +{{{ +<service-point id="Calculator" interface="org.apache.hivemind.management.Calculator"> + <invoke-factory> + <construct class="org.apache.hivemind.management.CalculatorImpl" /> + </invoke-factory> + <interceptor service-id="hivemind.management.PerformanceMonitorFactory"> + <exclude method="getSum"/> + <include method="add"/> + <include method="subtract"/> + </interceptor> +</service-point> +}}} -The mbean test.management.service.Calculator.PerformanceCollector displays these values for the Calculator service. -So just execute some calculations and watch the statistical data changing. -Double clicking the attribute values displays a graph. +The statistics are displayed by a MBean named like your service, with an additional name part "decorator=PerformanceCollector". == Monitor == @@ -189,7 +230,24 @@ Such a monitor can watch the attribute of another mbean (for example the average execution time of a service method) and send notifications, if a treshold is crossed. -The mbean test.management.service.CalculatorSumMonitor monitors the sum attribute of the calculator service (attribute DerivedGauge). Click the subscribe button on the notification tab to get notified when the calculator sum gets above 100. +The mbean test.management.service.CalculatorSumMonitor monitors the sum attribute of the calculator service (attribute DerivedGauge). + +{{{ + <service-point id="CalculatorSumMonitor" interface="javax.management.monitor.GaugeMonitorMBean"> + JMX Monitor that monitors the attribute Sum of the Calculator service + <invoke-factory model="primitive" > + <construct class="javax.management.monitor.GaugeMonitor" > + <set property="granularityPeriod" value="1000" /> + <set property="observedObject" value="HiveMind:module=test.management,type=service,id=Calculator" /> + <set property="observedAttribute" value="Sum" /> + </construct> + </invoke-factory> + </service-point> +}}} + +== Multiple applications in one JVM === + +todo .. = Implementation details = --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
