美文网首页
大数据监控 脚本

大数据监控 脚本

作者: baker_dai | 来源:发表于2019-04-16 08:44 被阅读0次

    #!/bin/sh

    hdfs dfsadmin -report |awk -F":" 'BEGIN{print "Node_Name      Status    Capacity  DFS_Used  Non_DFS    DFS_Remain DFS_Used%  Contact_Time ";print "--------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------  ";Flag=0}{  if($1=="Name") Flag=1;  if(Flag==1 && $1=="Name")                    printf ("%-16s",$2);  if(Flag==1 && $1=="Decommission Status ")    printf ("%-11s",$2);  if(Flag==1 && $1=="Configured Capacity")      printf ("%-11s",substr($2,index($2,"(")+1,index($2,")")-1-index($2,"(")));  if(Flag==1 && $1=="DFS Used")                printf ("%-11s",substr($2,index($2,"(")+1,index($2,")")-1-index($2,"(")));  if(Flag==1 && $1=="Non DFS Used")            printf ("%-11s",substr($2,index($2,"(")+1,index($2,")")-1-index($2,"(")));  if(Flag==1 && $1=="DFS Remaining")            printf ("%-11s",substr($2,index($2,"(")+1,index($2,")")-1-index($2,"(")));  if(Flag==1 && $1=="DFS Used%")                printf ("%-11s",$2);  if(Flag==1 && $1=="Last contact")            printf ("%s:%s\n",substr($2,6,15),$3);      if($1==null) Flag=0;      if(substr($1,1,14)=="Live datanodes")          {                                            Total_nodes=substr($1,index($1,"(")+1,index($1,")")-index($1,"(")-1);                                                                                      }  if(substr($1,1,14)=="Dead datanodes") {Dead_nodes=substr($1,index($1,"(")+1,index($1,")")-index($1,"(")-1);}    if($1=="Configured Capacity" && Flag==0) Total_Config_Capacity=substr($2,index($2,"(")+1,index($2,")")-1-index($2,"("));      if($1=="Present Capacity" && Flag==0)    Total_Present_Capacity=substr($2,index($2,"(")+1,index($2,")")-1-index($2,"("));  if($1=="DFS Remaining" && Flag==0)      Total_DFS_Remain=substr($2,index($2,"(")+1,index($2,")")-1-index($2,"("));  if($1=="DFS Used" && Flag==0)            Total_Used=substr($2,index($2,"(")+1,index($2,")")-1-index($2,"("));  if($1=="DFS Used%" && Flag==0)          Total_Used_per=$2;  }

    END{

    print "\n DFS Total Config_Capacity:  ",Total_Config_Capacity ;

    print  " DFS Total Present_Capacity: ",Total_Present_Capacity ;

    print  " DFS Total Used ( Used% ):  ",Total_Used,"(",Total_Used_per,")\n" ;

    print " DFS Total Datanodes:  ",Total_nodes ;

    print " DFS Dead  Datanodes:  ",Dead_nodes,"\n";

    }'

    #get every zookeeper

    echo "----------------------------------------------"

    echo "checking : Zookeeper status"

    #ssh admin1 'source /bigdata/.bash_profile;hostname;/bigdata/zookeeper/bin/zkServer.sh status'

    #ssh admin2 'source /bigdata/.bash_profile;hostname;/bigdata/zookeeper/bin/zkServer.sh status'

    #ssh admin3 'source /bigdata/.bash_profile;hostname;/bigdata/zookeeper/bin/zkServer.sh status'

    sh /bigdata/work/zk/check_zk.sh

    echo "----------------------------------------------"

    echo "checking : Namenode status"

    n=0

    n=`ssh admin1 'source /bigdata/.bash_profile;/bigdata/hadoop/bin/hdfs haadmin  -getServiceState nn1' | grep -i active | wc -l`

    m=0

    m=`ssh admin2 'source /bigdata/.bash_profile;/bigdata/hadoop/bin/hdfs haadmin  -getServiceState nn2' | grep -i active | wc -l`

    if [ $n -eq 1 ] ;then

      echo "admin1  is Namenode active"

    else

      echo "admin1  is Namenode standby"

    fi

    if [ $m -eq 1 ];then

      echo "admin2  is Namenode active"

    else

      echo "admin2  is Namenode standby"

    fi

    echo "------------------hdfs zkfc----------------------------"

    echo "checking : zkfc status"

    n=0

    n=`ssh admin1 'ps -ef|grep DFSZKFailoverController'|grep -v grep |wc -l`

    if [ $n -eq 1 ] ;then

      echo "admin1  zkfc status OK"

    else

      echo "admin1  zkfc status ERROR"

    fi

    m=0

    m=`ssh admin2 'ps -ef|grep DFSZKFailoverController'|grep -v grep|wc -l`

    if [ $m -eq 1 ] ;then

      echo "admin2  zkfc status OK"

    else

      echo "admin2  zkfc status ERROR"

    fi

    echo "------------------hdfs JournalNode----------------------------"

    echo "checking : JournalNode status"

    n=0

    n=`ssh admin1 'ps -ef|grep JournalNode'|grep -v grep|wc -l`

    if [ $n -eq 1 ] ;then

      echo "admin1  JournalNode status OK"

    else

      echo "admin1  JournalNode status ERROR"

    fi

    m=0

    m=`ssh admin2 'ps -ef|grep JournalNode'|grep -v grep|wc -l`

    if [ $m -eq 1 ] ;then

      echo "admin2  JournalNode status OK"

    else

      echo "admin2  JournalNode status ERROR"

    fi

    k=0

    k=`ssh admin3 'ps -ef|grep JournalNode'|grep -v grep|wc -l`

    if [ $k -eq 1 ] ;then

      echo "admin3  JournalNode status OK"

    else

      echo "admin3  JournalNode status ERROR"

    fi

    #echo "----------------------------------------------"

    #echo "checking : Hmaster status"

    #ssh admin1  'source .bash_profile;get-active-master.rb'

    #echo "checking : hadpmn04 status"

    #ssh admin2  'source .bash_profile;get-active-master.rb'

    echo "----------------------------------------------"

    echo "checking : yarn node status"

    相关文章

      网友评论

          本文标题:大数据监控 脚本

          本文链接:https://www.haomeiwen.com/subject/zxhvwqtx.html