Hadoop记录- Yarn Job MAX

#!/bin/sh
#yarn job status:NEW、NEW_SAVING、SUBMITTED、ACCEPTED、RUNNING、FINISHED、FAILED、KILLED
nnum=$(xx/yarn application -list -appStates NEW | wc -l)
nsnum=$(xx/yarn application -list -appStates NEW_SAVING | wc -l)
snum=$(xx/yarn application -list -appStates SUBMITTED | wc -l)
anum=$(xx/yarn application -list -appStates ACCEPTED | wc -l)
rnum=$(/xx/yarn application -list -appStates RUNNING | wc -l)
finum=$(xx/yarn application -list -appStates FINISHED | wc -l)
fanum=$(xxx/yarn application -list -appStates FAILED | wc -l)
knum=$(xxx/yarn application -list -appStates KILLED | wc -l)
let nnum=nnum-2
let nsnum=nsnum-2
let snum=snum-2
let anum=anum-2
let rnum=rnum-2
let finum=finum-2
let fanum=fanum-2
let knum=knum-2
vnum=($nnum $nsnum $snum $anum $rnum $finum $fanum $knum)
vkey=(NEW NEW_SAVING SUBMITTED ACCEPTED RUNNING FINISHED FAILED KILLED)
url="http://xxx/monitor/report/sendReport"
#yarn applicaiton -status application_1554987290796_77895
for (( i = 0 ; i < ${#vnum[@]} ; i++ ))
do
  for (( j = 0 ; j < ${#vkey[@]} ; j++ ))
  do
  if [ $i -eq $j ]
  then
  key="xx.yarn_job_state_"${vkey[$j]}"_count##xxx"
  value=${vnum[$i]}
  data="{\"key\":\"$key\",\"value\":$value}"
  echo $data
  cmd="curl -s -X POST -H 'Content-type':'application/json' -d '${data}' ${url}"
  sh -c "$cmd"
  fi
  done
done
#!/bin/sh
ip=xxx
port=8088
export HADOOP_HOME=/app/hadoop/bin
rmstate1=$($HADOOP_HOME/yarn rmadmin -getServiceState rm1)
rmstate2=$($HADOOP_HOME/yarn rmadmin -getServiceState rm2)
if [[ $rmstate1 == *active* ]]
then
   ip=xxx
fi
$HADOOP_HOME/yarn application -list -appStates RUNNING | awk '{print $1}' | grep -i "application" >appname.txt
curl http://$ip:$port/ws/v1/cluster/scheduler | jq . | sed 's/\"//g' > scheduler.json
sed -i '1,5d' scheduler.json 
sed -n -e :a -e '1,33!{P;N;D;};N;ba' scheduler.json > nscheduler.json
cat nscheduler.json | grep -i "queueName" | awk -F ": " '{print $2}' | awk -F "," '{print $1}' > qname.txt
cat nscheduler.json | grep -i "memory" | awk -F ": " '{print $2}' | awk -F "," '{print $1}' > memory.txt
line=$(cat memory.txt | wc -l)
for((j=2;j<$line;j=j+6))
do
  sed -n '$jp' memory.txt >> maxmemory.txt  
done
app=($(cat appname.txt | awk '{print $1}'))
for (( i = 0 ; i < ${#app[@]} ; i++ ))
do
    queue=$(curl http://$ip:$port/ws/v1/cluster/apps/${app[$i]} | jq . | sed 's/\"//g'  | grep -i "queue" | awk -F ":" '{print $2}')
    allocatedMB=$(curl http://$ip:$port/ws/v1/cluster/apps/${app[$i]} | jq . | sed 's/\"//g'  | grep -i "allocatedMB" | awk -F ":" '{print $2}')
    nparr=($(cat nscheduler.json | grep -i "numPendingApps" | awk -F ": " '{print $2}' | awk -F "," '{print $1}'))
    for((j=0;j<=${#nparr[@]};j++))
    do
       if [${nparr[$j]} -gt 10 ]
       then
          qname=$(sed -n '$jp' qname.txt)
          mem=$(sed -n '$jp' maxmemory.txt)
          if [ $qname -eq $queue ]
          then
                 rate=$(echo "sclae=2; $allocatedMB/$mem" | bc) 
                 if [ $rate -gt 0.2 ]
                 then
                    $HADOOP_HOME/yarn application  -kill  ${app[$i]}
                 fi
          fi
        fi 
    done
done
#查看任务的详细信息
#$HADOOP_HOME/yarn applicaiton -status ${app[$i]}
curl http://$ip:$port/ws/v1/cluster/apps/application_1554987290796_688678
#查看任务状态
curl http://$ip:$port/ws/v1/cluster/apps/application_1409421698529_0012/state
#kill任务
curl -v -X PUT -d '{"state": "KILLED"}''http://$ip:$port/ws/v1/cluster/apps/application_1409421698529_0012'
#队列资源信息
curl http://$ip:$port/ws/v1/cluster/scheduler
#查看指定队列的所有任务:
curl http://$ip:$port/ws/v1/cluster/apps?queue=default
#查看整个集群的指标
curl http://$ip:$port/ws/v1/cluster/metrics
#查看队列的状态
yarn queue -status default
posted @ 2019-04-17 18:22  信方  阅读(937)  评论(0编辑  收藏  举报