jvm memory area monitoring tool

        The previous article has introduced some monitoring tools that come with JDK, but these tools are all based on the text interface, and it is impossible to intuitively see the fluctuations in the running of the program. This section introduces some graphical monitoring tools for you to update. Simple and easy monitoring to use.

        First, let’s talk about a few officially developed graphical monitoring tools:

 

        1.jvmstat
        jvmstat is a graphical version of jstat, which is officially provided by Java, and the latest version is 3.0.

        Download address: http://www.oracle.com/technetwork/java/jvmstat-142257.html

 

        After downloading, unzip it to get the following directory structure:


        The directory structure is relatively clear, and it is easy to distinguish the functions and functions of each directory:
        bat: windows startup program

        bin: linux startup program

        docs: related documentation

        etc: linux related dependencies

        jars: related jar packages 

 

        Before using jvmstat, you need to configure the corresponding environment variables. The environment variables are configured as follows:

Shell code  Favorite code
  1. JVMSTAT_HOME: jvmstat installation directory  
  2. JVMSTAT_JAVA_HOME: The directory where the JDK is located, the same value as JAVA_HOME  

 

        After configuring the two environment variables, you can run jvmstat. The running command is:

Shell code  Favorite code
  1. visualgc pid  
  2. #windows system enter the bat directory and run this command  
  3. #linux system enter the bin directory and run this command  

 

        After running, the interface is automatically opened and the corresponding content is displayed, as shown in the figure:


 

         From jvmstat, we can clearly observe the time consumed by assembly, loading, garbage collection and the memory usage of each area. In the figure, the memory usage of s0 and s1 is always mutually exclusive, that is, at most one will be in use. So jvmstat can only be used as a basic graphical monitoring tool.


        评论:jvmstat 作为一款基本的JVM 图形化监控工具,优点就是简单易用,我们可以非常直观的观察堆内存的使用情况,当然仅仅为堆内存,所以jvmstat 具有一定的局限性。 

 

        2.JConsole

        JConsole 是一个基于JMX 的图形监控工具,用于连接正在运行的JVM,与前面提到的jvmstat 类似的图形监控程序,可以以图表化的形式显示各种数据,并可通过远程连接监视远程的服务器VM 情况,此类工具可以较直观观察各种变化,但比较耗费资源。

        在JDK 1.5之后JConsole 已经成为JDK 自带监控工具,只需要在命令行状态下输入:

Java代码  Favorite code
  1. jconsole  

        即可开启监控界面,界面如下:


        选择本地监控还是远程监控。

        进入监控界面后,会有一些基本选项可以选择,例如内存,线程,类等。

        选择内存选项后会显示堆与非堆内存等使用情况。

 

        概述选项:监控JVM和一些监控变量的信息。 
        内存选项:内存使用信息 
        线程选项:线程使用信息 
        类选项:类调用信息 
        VM摘要:JVM的信息 
        MBean选项:所有MBean 的信息MBean 展示了所有以一般形式注册到JVM 上的MBean 。MBean 允许你获取所有的平台信息,包括那些不能从其他标签页获取到的信息。注意,其他标签页上的一些信息也在MBean 这里显示。另外,你可以使用 MBean 标签管理你自己的应用的MBean。

 

        评论:与jvmstat 相比jconsole 就要强大的多了,从jconsole 中可以不光光监控到内存情况,还可以监控例如:线程,类,JVM参数等等高级信息。jconsole 还可以根据内存等使用情况手动执行GC 清理,这给我们的程序监控与良好运行带来了很大的便利。值得注意的是jconsole可以同时监控多个JVM 进程,在jconsole 中可以轻松的切换监控界面。


        3.Java VisualVM 
        JDK1.6 中Java 引入了一个新的可视化的JVM 监控工具:Java VisualVM。

        VisualVM 官方网站:http://visualvm.java.net/

        VisualVM 提供在Java 虚拟机上运行的Java 应用程序的详细信息。在VisualVM 的图形用户界面中可以方便、快捷地查看多个Java 应用程序的相关信息。


        运行VisualVM 非常简单,只需在命令行状态下输入:

Java代码  Favorite code
  1. jvisualvm  

 
        VisualVM 便会自动启动,之后可以看到如下界面:



        通过起始页的提示进入相应的学习文档页面,里面有丰富的教程及讲解,并且都是中文的!


        "本地"列表下列出在本机运行的Java 程序的资源占用情况,如果本地有Java程序在运行的话启动VisualVM 即可看到相应的程序名,点击程序名打开相应的资源监控菜单,以图形的形式列出程序所占用的CPU、Heap、PermGen、类、线程的 统计信息,如图所示:


概述选项

监控选项

线程选项
   

        "远程"列表下列出远程主机上的Java 程序的资源占用情况,但需要在远程主机上运行jstatd 守护程序

        更多的应用及用法可以参照官方文档:

        http://visualvm.java.net/zh_CN/gettingstarted.html?Java_VisualVM

 

        评论:VisualVM 较JConsole 又强大了不少,其中又增加了许多功能与信息,通过VisualVM 可以更加直观的观察各种内容的详细信息。

 

        4.YourKit Java Profiler

        YourKit 是一个用于分析Java 与.NET 应用程序的智能工具,YourKit Java Profiler 已经被IT 专业人士与分析师公认为最好的分析工具。通过YourKit 技术解决方案可以以非常高的的专业水平分析出CPU 与内存使用情况。
        YourKit Java Profiler 还获得了Java Developer's Journal(Java 开发者杂志)的编辑选择奖,其功能的强大可见一斑。

        YourKit 网站官方:http://www.yourkit.com
        YourKit Java Profiler 下载地址:http://www.yourkit.com/download/index.jsp
        YourKit Java Profiler 提供了Java 与.NET 两种语言的支持,并且支持基本所有操作系统,目前最新版本为12.0.6。


        下载界面如下:


 

        下载并安装:
 

 

        安装完成后一次运行会提示授权本软件,对于个人用户其实可以免费使用YourKit Java Profiler,只需在下载页面下方填写相应授权信息即可获得授权码,如图所示:

 

        After authorization, the welcome page will be displayed, as shown below:

        On the welcome page, you can choose to monitor the running JVM process, install the eclipse plug-in, use the tutorial and so on.

 

        Checking "Show all running JVMs" will display all JVM processes in the drop-down list, select one of them and click to enter the monitoring interface:
        the above picture is the monitoring interface for CPU-related information, from which you can observe the CPU usage and other information .

 

        You can also open the memory management interface to view the occupancy of various memory in the JVM:

 

        Of course, the function of YourKit Java Profiler is not limited to this. We can also learn more advanced monitoring functions by referring to the YourKit Java Profiler documentation. Official tutorial address: http://www.yourkit.com/docs/index.jsp

 

       Comments: YourKit Java Profiler can be said to be extremely powerful. Almost all YourKit Java Profiler you can think of has been implemented, so I don’t need to say more about such a powerful tool. You can even buy its paid version, I believe it will definitely Surprised the boys. This section is only for the purpose of attracting more and more advanced features. You need to explore yourself in practice.

 

       Graphical monitoring tools can enable us to view the running status of the current program more intuitively during the running of the program, so as to make corresponding judgments. Monitoring the program can make work more convenient, but building a stable and efficient system is the ultimate goal of continuous pursuit. .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325789955&siteId=291194637