大數(shù)據(jù)監(jiān)控 腳本

#!/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"

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容