Skip to content

Instantly share code, notes, and snippets.

@mtsuszycki
Created June 19, 2016 21:16
Show Gist options
  • Save mtsuszycki/7df0ba08889d373cfcb87e8a9cffbaf6 to your computer and use it in GitHub Desktop.
Save mtsuszycki/7df0ba08889d373cfcb87e8a9cffbaf6 to your computer and use it in GitHub Desktop.
Basic functions to do hadoop (hdfs) health check #bigdata #hadoop #bash #hdfs
#!/bin/bash
function emsg() { email_body="$email_body\n${1}"; }
function email()
{
local subject=$1 rcpt=$2
echo -e "$email_body\n\n\n" | mail -s "$subject" -r noreply@somedomain.com "$rcpt"
}
function hadoop_nn_state()
{
local h=$1 ret state
state=`curl -s "http://$h:50070/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus" | grep '\"State\" :'`
ret=$?
[ $ret -ne 0 ] && { emsg "Hadoop $h name node problem, curl returned $ret"; return $ret; }
state=${state//\"/}
state=${state//,/}
state=${state##*:}
state=${state// /}
[ x$state != x'active' ] && { emsg "Hadoop $h name node problem, it is not active, current state: $state"; return 1; }
dbg "Hadoop NameNode: $h state is $state"
return 0
}
function cluster_status()
{
local a nr dnodes=$1
while read a; do
echo $a | grep -q "Live datanodes"
[ $? -ne 0 ] && continue
nr=${a##*(}
nr=${nr%%)*}
[ $nr -ne $dnodes ] && { emsg "Hadoop cluster problem: live datanodes $nr ,$a"; return ; }
done < <(HADOOP_USER_NAME=hdfs /usr/local/hadoop/bin/hadoop dfsadmin -report 2>/dev/null)
}
hadoop_nn_state 192.168.1.1
cluster_status 3 # arg is number of data nodes
[ "$email_body" != '' ] && email 'HDFS problem' some.email@mydomain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment