The previous two JMX remote monitoring Tomcat server is not configured with a password, the following describes the user password configuration when Tomcat monitoring.
Specific Tomcat address: Http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#Enabling_JMX_Remote
Note: This syntax are for Microsoft Windows. The command has been on the same line. It's wrapped to being more readable. If Tomcat is running as a Windows service, use the IT configuration dialog to set Java options for the service. For un*xes Remove from beginning of the line "set "
.
|
|
|
|
set Catalina_opts=-dcom.sun.management.jmxremote- dcom.sun.management.jmxremote.port=%my.jmx.port%-dcom.sun.management.jmxremote.ssl=false- Dcom.sun.management.jmxremote.authenticate=false |
|
|
|
|
- If you require authorization, add and change this:
tr>
|
|
|
|
-dcom.sun.management.jmxremote.authenticate=true-dcom.sun.management.jmxremote.password.file=. /conf/jmxremote.password-dcom.sun.management.jmxremote.access.file=. /conf/jmxremote.access |
|
|
|
|
- Edit the Access authorization file $CATALINA _base/conf/jmxremote.access :
|
|
|
|
monitorrole readonlycontrolrole readwrite |
|
|
|
|
- Edit the password file $CATALINA _base/conf/jmxremote.password :
|
|
|
|
Monitorrole Tomcatcontrolrole Tomcat |
|
|
|
|
Tip: The password file should be read-only and only accessible by the operating system, user Tomcat is running as.
The contents are as follows:
1, edit Tomcat/bin in the Catalina.bat. If you configure permissions, you need to set Autenticate to True to add the following two lines of code in 1 to the top row, note that all of these commands must be on one line!.
2. Create a new two files in the tomcat/conf directory:jmxremote.access and Jmxremote.password
The first file is the role information, the second one is the password information (modifiable).
After configuring the above information: when we start Tomcat, Tomcat appears flashing, the above-mentioned meaning is a permission issue.
The solution is to select the Tomcat folder, right-----"Properties"--"security"--point "advanced"--"Change Permissions"--remove "inherit from parent ...."-Pop-up window select "Delete" This removes all access rights. Then choose "Add"-"advanced"-"Find Now", select your user (or user group, if the user does not choose the Users group), example administrator (current computer permissions), click "OK", "OK". Come to the Permission Entry window, tick "Full Control", click "OK", restart on it.
Realize:
When there is no password, we use Connect (Jmxserviceurl serviceurl) of the Jmxconnectorfactory factory class to create a connection to the connector server at the given address. After setting the password, connect (jmxserviceurl serviceurl, map<string,?> Environment) is required,
Set map to store environment.put ("Jmx.remote.credentials", credentials); configuration information.
String[] Credentials = new string[] {"Monitorrole", "Tomcat"};
The specific implementation is as follows:
Package Pyc.jvm.monitor;import Java.io.ioexception;import Java.lang.management.classloadingmxbean;import Java.lang.management.managementfactory;import Java.lang.management.memorymxbean;import Java.lang.management.memoryusage;import Java.lang.management.operatingsystemmxbean;import Java.lang.management.threadmxbean;import Java.net.malformedurlexception;import Java.util.HashMap;import Java.util.map;import Java.util.timer;import Java.util.timertask;import Java.util.concurrent.timeunit;import Javax.management.attributenotfoundexception;import Javax.management.instancenotfoundexception;import Javax.management.mbeanexception;import Javax.management.mbeanserverconnection;import Javax.management.reflectionexception;import Javax.management.remote.jmxconnector;import Javax.management.remote.jmxconnectorfactory;import javax.management.remote.jmxserviceurl;/** * Created: 2014-12-5 am 11 : 06:34 * * @author zhangtianyou * @version 2.2 */public class JMXTest3 {private final static String service_1 = "ServIce:jmx:rmi:///jndi/rmi://192.168.85.54:8787/jmxrmi ";/** * @param args */public static void main (string[] args) {// 10 seconds to call a timer timer = new timer (); Timer.schedule (new JMXTest3 (). New Monitortask (Service_1), 0, 10000);} Private class Monitortask extends TimerTask {private string service;public monitortask (String service) {This.service = Ser Vice;} @Overridepublic void Run () {jmxmonitor (service);}} private static void Jmxmonitor (String service) {Jmxconnector Jmxconnector = null;try {Jmxserviceurl serviceurl = new Jmxse Rviceurl (service); map<string, string[]> environment = new hashmap<string, string[]> ();//username password, The password in the Jmxremote.password file string[] credentials = new string[] {"Monitorrole", "Tomcat"};environment.put (" Jmx.remote.credentials ", credentials); jmxconnector = Jmxconnectorfactory.connect (serviceurl, Environment); Mbeanserverconnection mbeanserverconnection = Jmxconnector.getmbeanserverconnection ();// Get MemoryMXBeanSystem.out.println ("\nmemory"); Memorymxbean Memorymxbean = MAnagementfactory.newplatformmxbeanproxy (Mbeanserverconnection,managementfactory.memory_mxbean_name, Memorymxbean.class); Memoryusage heapmemoryusage = Memorymxbean.getheapmemoryusage (); System.out.println ("Heapmemoryusage:"); SYSTEM.OUT.PRINTLN ("committed =" + CONVERTKB (heapmemoryusage.getcommitted ())); System.out.println ("init =" + CONVERTKB (Heapmemoryusage.getinit ())); System.out.println ("max =" + Convertkb (Heapmemoryusage.getmax ())); System.out.println ("used =" + CONVERTKB (heapmemoryusage.getused ())); Memoryusage nonheapmemoryusage = Memorymxbean.getnonheapmemoryusage (); System.out.println ("\nnonheapmemoryusage:"); SYSTEM.OUT.PRINTLN ("committed =" + CONVERTKB (nonheapmemoryusage.getcommitted ())); System.out.println ("init =" + CONVERTKB (Nonheapmemoryusage.getinit ())); System.out.println ("max =" + Convertkb (Nonheapmemoryusage.getmax ())); System.out.println ("used =" + CONVERTKB (nonheapmemoryusage.getused ()));//Get ThreadMXBeanSystem.out.println ("\ Nthread "); Threadmxbean Threadmxbean = ManagementFactory.newplatformmxbeanproxy (Mbeanserverconnection,managementfactory.thread_mxbean_name,threadmxbean.class); System.out.println ("ThreadCount =" + Threadmxbean.getthreadcount ()); System.out.println ("Daemonthreadcount =" + Threadmxbean.getdaemonthreadcount ()); System.out.println ("Peakthreadcount =" + Threadmxbean.getpeakthreadcount ()); System.out.println ("currentthreadcputime =" + Threadmxbean.getcurrentthreadcputime ()); System.out.println ("currentthreadusertime =" + Threadmxbean.getcurrentthreadusertime ()); System.out.println ("\nclassloading"); Classloadingmxbean Classloadingmxbean = Managementfactory.newplatformmxbeanproxy (MBeanServerConnection, Managementfactory.class_loading_mxbean_name,classloadingmxbean.class);//The number of classes currently loaded into the Java Virtual machine System.out.println (" Loadedclasscount = "+ Classloadingmxbean.getloadedclasscount ());//The total number of Java virtual machines starting to execute to classes that are currently loaded. System.out.println ("Totalloadedclasscount =" + Classloadingmxbean.gettotalloadedclasscount ());//Java The total number of classes that the virtual machine started to perform to the currently unloaded. System.out.println ("UnloadeDclasscount = "+ Classloadingmxbean.getunloadedclasscount ()); System.out.println ("\ncpu"); Operatingsystemmxbean Operatingsystemmxbean = Managementfactory.newplatformmxbeanproxy (Mbeanserverconnection,managementfactory.operating_system_mxbean_name, Operatingsystemmxbean.class); System.out.println ("availableprocessors =" + operatingsystemmxbean.getavailableprocessors ());d ouble ratio = 0.0;long Start = System.currenttimemillis (); long Startc;try {STARTC = (long) Mbeanserverconnection.getattribute ( Operatingsystemmxbean.getobjectname (), "Processcputime"), try {TimeUnit.SECONDS.sleep (5);} catch ( Interruptedexception e) {e.printstacktrace ();} Long end = System.currenttimemillis (); Long ENDC = (long) Mbeanserverconnection.getattribute ( Operatingsystemmxbean.getobjectname (), "processcputime"); int availableprocessors = Operatingsystemmxbean.getavailableprocessors (); ratio = (ENDC-STARTC)/1000000.0/(End-start)/availableprocessors;} catch (Attributenotfoundexception E1) {//TODO auto-generated catchBlocke1.printstacktrace ();} catch (Instancenotfoundexception E1) {//TODO auto-generated catch Blocke1.printstacktrace ();} catch (Mbeanexception E1) {//TODO auto-generated catch Blocke1.printstacktrace ();} catch (Reflectionexception E1) {//TODO auto-generated catch Blocke1.printstacktrace ();} SYSTEM.OUT.PRINTLN ("Cup usage" + round (ratio * 100) + "%");} catch (Malformedurlexception e) {e.printstacktrace (); SYSTEM.OUT.PRINTLN ("illegal serviceurl");} catch (IOException e) {e.printstacktrace ();} finally {try {if (jmxconnector! = null) {Jmxconnector.close ();}} catch (Ioexc Eption e) {e.printstacktrace ();}}} private static String convertkb (long src) {if (src <= 0L) {return "0KB";} Double conversrc = Src/1024/1024;return round (conversrc) + "MB";} private static float round (double src) {return (float) (Math.Round (SRC * 100))/100;}}
The effect of nesting in Java EE is as follows:
JMX realizes the remote server Tomcat system monitoring three