zoukankan      html  css  js  c++  java
  • JMX Monitor Hadoop

    1.    Config  $HADOOP_HOME/conf/hadoop-env.sh   for all  the nodes :

    exportHADOOP_HOME=/opt/hadoop-1.0.0

    exportHADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote.port=9191-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=$HADOOP_HOME/conf/jmxremote.password-Dcom.sun.management.jmxremote.access.file=$HADOOP_HOME/conf/jmxremote.access   $HADOOP_NAMENODE_OPTS"

    exportHADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote.port=9292 -Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=true-Dcom.sun.management.jmxremote.password.file=$HADOOP_HOME/conf/jmxremote.password-Dcom.sun.management.jmxremote.access.file=$HADOOP_HOME/conf/jmxremote.access  $HADOOP_DATANODE_OPTS"

    exportHADOOP_JOBTRACKER_OPTS="-Dcom.sun.management.jmxremote.port=9393-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=true-Dcom.sun.management.jmxremote.password.file=$HADOOP_HOME/conf/jmxremote.password-Dcom.sun.management.jmxremote.access.file=$HADOOP_HOME/conf/jmxremote.access  $HADOOP_JOBTRACKER_OPTS"

    exportHADOOP_TASKTRACKER_OPTS="-Dcom.sun.management.jmxremote.port=9494-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true-Dcom.sun.management.jmxremote.password.file=$HADOOP_HOME/conf/jmxremote.password-Dcom.sun.management.jmxremote.access.file=$HADOOP_HOME/conf/jmxremote.access  $HADOOP_TASKTRACKER_OPTS"

    Create the file jmxremote.password :

    admin  admin

    Create the file jmxremote. access  :

    admin  readonly

    change  mode of files:

    chmod600 jmxremote.password

    chmod600 jmxremote.password

     

    2. Connect to node by JMX:

    The URL:

    service:jmx:rmi://jdni/rmi://server1:9191/jmxrmi

    service:jmx:rmi://jdni/rmi://server2:9292/jmxrmi

    service:jmx:rmi://jdni/rmi://server1:9393/jmxrmi

    service:jmx:rmi://jdni/rmi://server2:9494/jmxrmi


    /*
     * @author Hui
     */
    public class NewClass {
    
        public static void main(String[] args) throws Exception {
            JMXServiceURL target = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://server1:9191/jmxrmi");
            Map env = new HashMap();
            env.put(JMXConnector.CREDENTIALS, new String[]{"admin", "admin"});
            JMXConnector connector = JMXConnectorFactory.connect(target, env);
            MBeanServerConnection con = connector.getMBeanServerConnection();
            ObjectName obj = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState");
            long capacityTotal = (long) con.getAttribute(obj, "CapacityTotal");
            long capacityUsed = (long) con.getAttribute(obj, "CapacityUsed");
            long capacityRemain = (long) con.getAttribute(obj, "CapacityRemaining");
            int totalLoad = (int) con.getAttribute(obj, "TotalLoad");
            long blocksTotal = (long) con.getAttribute(obj, "BlocksTotal");
            long filesTotal = (long) con.getAttribute(obj, "FilesTotal");
            long pendingRepBlocks = (long) con.getAttribute(obj, "PendingReplicationBlocks");
            long underRepBlocks = (long) con.getAttribute(obj, "UnderReplicatedBlocks");
            long scheduledRepBlocks = (long) con.getAttribute(obj, "ScheduledReplicationBlocks");
            String fsFSState = (String) con.getAttribute(obj, "FSState");
            StringBuffer sb = new StringBuffer();
            sb.append("FS_NAME_SYSTEM_STATE:")
                    .append("[").append("capacityTotal").append("]=").append(capacityTotal).append(",")
                    .append("[").append("capacityUsed").append("]=").append(capacityUsed).append(",")
                    .append("[").append("capacityRemain").append("]=").append(capacityRemain).append(",")
                    .append("[").append("totalLoad").append("]=").append(totalLoad).append(",")
                    .append("[").append("blocksTotal").append("]=").append(blocksTotal).append(",")
                    .append("[").append("filesTotal").append("]=").append(filesTotal).append(",")
                    .append("[").append("pendingRepBlocks").append("]=").append(pendingRepBlocks).append(",")
                    .append("[").append("underRepBlocks").append("]=").append(underRepBlocks).append(",")
                    .append("[").append("scheduledRepBlocks").append("]=").append(scheduledRepBlocks).append(",")
                    .append("[").append("fsFSState").append("]=").append(fsFSState);
            System.out.println(sb.toString());
    
        }




    The result  is:

    FS_NAME_SYSTEM_STATE:[capacityTotal]=79349178368, [capacityUsed]=1273987072, [capacityRemain]=61595832320,[totalLoad]=2, [blocksTotal]=74, [filesTotal]=105, [pendingRepBlocks]=0, [underRepBlocks]=73,[scheduledRepBlocks]=0, [fsFSState]=Operational

    
    


  • 相关阅读:
    MySQL修改表中字段的字符集
    JMM内存模型相关笔记整理
    可重入锁与不可重入锁
    ForkJoin、并行流计算、串行流计算对比
    CyclicBarrier的用法
    git笔记整理-learnGitBranching
    Git 学习相关笔记
    《0day2》学习笔记-part5(书目第十二章(上))
    《0day2》学习笔记-part4(书目第八、九、十、十一章)
    《0day2》学习笔记-part3(书目第六、七章)
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276414.html
Copyright © 2011-2022 走看看