Hadoop jar配置使用JMX进行远程JVM监控

背景:  编写了一个MapReduce程序,发现该程序内存占用非常多,需要有一种方法来分析内存详细的占用情况。

    可以使用linux上的pmap –d <PID>来看进程逻辑地址空间使用情况,但是会有很多anno区域,显然这不能够满足同学们的好奇心。 

     在这篇文章Eclipse远程调试HDP源代码中,提到使用JMX的方法对HDP进行远程调试。JMX(Java Management Extensions,即Java管理扩展),望文生义一下,可知这个机制是与管理相关的。在这个机制的基础上,可以对JVM的运行情况进行实时的分析。方法如下:

     1. 修改vim /usr/hdp/2.3.0.0-2557/hadoop/etc/hadoop/hadoop-env.sh的配置,添加与JMX相关的参数:

     Image

     文字版本(添加45行的内容)

42
 43 # The following applies to multiple commands (fs, dfs, fsck, distcp etc)
 44 export HADOOP_CLIENT_OPTS="-Xmx${HADOOP_HEAPSIZE}m $HADOOP_CLIENT_OPTS"
 45 export HADOOP_CLIENT_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremo
    te.local.only=false   -Djava.net.preferIPv4Stack=true  -Dcom.sun.management.jmxremote.port=1499 $HADOOP_CLIENT_OPTS "

      这个会在执行hadoop jar的机器上,开启一个端口,这个端口号由-Dcom.sun.management.jmxremote.port=1499这个参数决定。

    2.启动一个mapreduce程序,bash-4.1$ hadoop jar /home/yanliming/workspace/mosaicTest/videoMapreduce/videoMapreduce-1.0-SNAPSHOT.jar /tmp/yanliming/Wildlife.wmv /tmp/ryj/result/output012

       在启动mapreduce的集群上,可以看到刚才配置的端口已经起来:

       Image

     3. 下载visualVM  地址:http://visualvm.java.net/download.html 

      在visualVM中,配置远程机器的IP和端口号,进行实时的监控:Image

   

原文地址:https://www.cnblogs.com/justinzhang/p/5529865.html