Use JMX to monitor most Java applications

Source: Internet
Author: User

JMX (Java Management Extensions, Java Management Extensions) is a framework for embedding management functions for applications, devices, systems, and so on. JMX can span a range of heterogeneous operating system platforms, system architectures, and network transport protocols, and flexibly develop seamless, integrated systems, networks, and service management applications.

In fact, we can use JMX to monitor the operation of some Java applications, as well as the application of some of the service classes written by ourselves.

Here are the JMX source codes we use to monitor

Package com.shine.framework.Jmx; Import Java.util.HashMap; Import Java.util.Map; Import javax.management.MBeanServerConnection; Import Javax.management.ObjectName; Import Javax.management.remote.JMXConnector; Import Javax.management.remote.JMXConnectorFactory; Import Javax.management.remote.JMXServiceURL; public class Jmxmanager {/** * Establish connection * * @param IP * @param jmxport * @return/public static mbeanserverconnection creat Embeanserver (string IP, String jmxport, String userName, string password) {try {string jmxurl = ' Service:jmx:rmi:///jndi /rmi://"+ IP +": "+ jmxport +"/jmxrmi "; JMX//url Jmxserviceurl serviceurl = new Jmxserviceurl (Jmxurl); Map map = new HashMap (); String[] Credentials = new string[] {userName, password}; Map.put ("Jmx.remote.credentials", credentials); Jmxconnector connector = jmxconnectorfactory.connect (serviceurl, map); Mbeanserverconnection mbsc = Connector.getmbeanserverconnection (); return MBSC; catch (Exception e) {//E.printstacktrace (); System. ERR.PRINTLN (IP + "middleware cannot be reached"); return null; /** * Get ALL Properties * * @param mbeanserver * @param objname * @return/public static Map Getallattribute (Mbeanserverconnectio n Mbeanserver, objectname objname) {if (Mbeanserver = null | | objname = NULL) throw new IllegalArgumentException (); try {return null;} catch (Exception e) {return null;}} /** * Use Mbeanserver to get the [Objattr] property value * <p> * static code for an Mbean with the object name [objname]: Return Mbeanserver.getattribute (objectname Name, String attribute * * @param mbeanserver *-mbeanserver instance * @param objname *-Mbean Object name * @param objattr *-Mbean A property name * @return attribute value */private static Object getattribute (mbeanserverconnection mbeanserver, objectname objname, String o BJATTR) {if (Mbeanserver = null | | | objname = NULL | | | objattr = NULL) throw new IllegalArgumentException (); try {retur N string.valueof (Mbeanserver.getattribute (objname, "currentthreadsbusy")); catch (Exception e) {return null;}} }

Let me add a few more to how to open Tomcat and WebLogic services.

First in the domain to find the need to monitor the project, such as Sourceview, D:/weblogic/user_projects/domains/sourceview. And then open it's Startweblogic.cmd plus set java_options=%java_options%.
-dcom.sun.management.jmxremote
-dcom.sun.management.jmxremote.port=8050
-dcom.sun.management.jmxremote.ssl=false
-dcom.sun.management.jmxremote.authenticate=true
-dcom.sun.management.jmxremote.access.file=d:/temp/jmxremote.access
-dcom.sun.management.jmxremote.password.file=d:/temp/jmxremote.password

Tomcat to join JMX monitoring is easier than WebLogic, can get more MIB than WEBLOGIC10, first we find under the Bin directory:

Catalina.bat is used to modify the jmx of Windows, catalina.sh is used to modify the Linux jmx. The exact method of modification is the same.
In rem-----Execute the requested Command---------------------------------------
Join:
Set Java_opts=-dcom.sun.management.jmxremote
-dcom.sun.management.jmxremote.port=8050
-dcom.sun.management.jmxremote.ssl=false
-dcom.sun.management.jmxremote.authenticate=true
-dcom.sun.management.jmxremote.access.file=d:/temp/jmxremote.access
-dcom.sun.management.jmxremote.password.file=d:/temp/jmxremote.password

If you have the same hint that you must limit the Read permission for the password file, you can follow the same solution as WebLogic.
Or:
Set Java_opts=-dcom.sun.management.jmxremote
-dcom.sun.management.jmxremote.port=8050
-dcom.sun.management.jmxremote.ssl=false
-dcom.sun.management.jmxremote.authenticate=false
-dcom.sun.management.jmxremote.access.file=d:/temp/jmxremote.access
-dcom.sun.management.jmxremote.password.file=d:/temp/jmxremote.password

Annex: Temp/jmxremote.access and Temp/jmxremote.password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.