An example of using JMX to monitor VMS

Source: Internet
Author: User

Package com. Wonder;

Import java. Lang. Management. classloadingmxbean;
Import java. Lang. Management. garbagecollectormxbean;
Import java. Lang. Management. managementfactory;
Import java. Lang. Management. memorymxbean;
Import java. Lang. Management. memoryusage;
Import java. Lang. Management. runtimemxbean;
Import java. util. List;

Public class testmain extends thread {

Runtimemxbean mxbean;

Private void setfactory (){
Mxbean = managementfactory. getruntimemxbean ();
// Obtain the attributes of the Virtual Machine
System. out. println ("===================== virtual machine information =======================" );
System. Out. println ("virtual machine provider:" + mxbean. getvmvendor ());
System. Out. println ("Virtual Machine name:" + mxbean. getvmname ());
System. Out. println ("current class path:" + mxbean. getclasspath ());
System. Out. println ("process number @ machine:" + mxbean. getname ());
System. Out. println ("running time (MS):" + mxbean. getuptime ());

// Class Management Interface
System. out. println ("===================== class loading information ============================ ");
Classloadingmxbean aclassloadingmxbean = managementfactory
. Getclassloadingmxbean ();
System. Out. println ("Total number of loaded classes :"
+ Aclassloadingmxbean. getloadedclasscount ());
System. Out. println ("verbose status:" + aclassloadingmxbean. isverbose ());

// Memory Management Interface
System. out. println ("===================== memory information ========================== = ");
Memorymxbean amemorymxbean = managementfactory. getmemorymxbean ();
System. Out. println ("number of terminated pending instances :"
+ Amemorymxbean. getobjectpendingfinalizationcount (); // returns the approximate number of objects whose suspension is terminated.
// Return the current usage of non-heap memory used by the Java Virtual Machine
Memoryusage amemoryusage = amemorymxbean. getnonheapmemoryusage (); // memory obtained from the system (in bytes) when the VM is started)
System. Out. println ("memory obtained from the system during VM startup:" + amemoryusage. getinit (); // indicates the amount of memory in use (in bytes)
System. Out. println ("memory used currently:" + amemoryusage. getused (); // indicates that
// Java
// The amount of memory used by the VM (in bytes)

System. Out. println ("amount of memory used by the VM:" + amemoryusage. getcommitted (); // indicates the maximum amount of memory that can be used for memory management (in bytes)
System. Out. println ("Initial memory size for memory management:" + amemoryusage. getinit ());
System. Out. println ("maximum memory size for memory management:" + amemoryusage. getmax ());
System. Out. println ("Overall description:" + amemoryusage. tostring ());

List <garbagecollectormxbean> agcmxbeans = managementfactory. getgarbagecollectormxbeans ();
Garbagecollectormxbean agcmxbean = agcmxbeans. Get (0 );
System. out. println ("=================== GC information ============================ = ");
System. Out. println ("Total number of collections:" + agcmxbean. getcollectioncount ());
System. Out. println ("collection time:" + agcmxbean. getcollectiontime ());
System. Out. println ("Memory Manager valid:" + agcmxbean. isvalid ());
System. Out. println ("Memory Pool name:" + agcmxbean. getmemorypoolnames () [0]);
System. Out. println ("Memory Pool name:" + agcmxbean. getmemorypoolnames () [1]);


System. out. println ("****************** end ******************* ***");
}

Public void run (){
Try {
While (true ){
Setfactory ();
Sleep (1000 );
}
} Catch (interruptedexception e ){
E. printstacktrace ();
}

}

Public static void main (string [] ARGs ){
Testmain atest = new testmain ();
Atest. Start ();
}

}

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.