Skip to content

Commit

Permalink
Add Chapter 17 scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Havanki committed Mar 26, 2017
1 parent 6149f0b commit 429750e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ch17/dfs_used_metric.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

dfs_used=$(/opt/hadoop/bin/hdfs dfsadmin -report | \
grep -m 1 "DFS Used%" | cut -d ' ' -f 3 | sed 's/%//g')

/usr/local/bin/aws cloudwatch put-metric-data --metric-name DFSUsed \
--namespace HadoopClusters --unit Percent --value "$dfs_used" \
--dimensions Cluster=MyFirstCluster
7 changes: 7 additions & 0 deletions ch17/yarn_mem_metric.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

yarn_mem_used=$(/path/to/yarnmem.sh)

/usr/local/bin/aws cloudwatch put-metric-data --metric-name YarnMemUsage \
--namespace HadoopClusters --unit Percent --value "$yarn_mem_used" \
--dimensions Cluster=MyFirstCluster
20 changes: 20 additions & 0 deletions ch17/yarnmem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

used_total=0
available_total=0

for n in $(yarn node -list 2>/dev/null | grep -v Total | grep -v Node-Id | \
cut -d ' ' -f 1); do
mem="$(yarn node -status "$n" 2>/dev/null | grep 'Memory-' | \
cut -d ' ' -f 3 | sed 's/MB//g' | xargs)"
used=${mem%% *}
available=${mem##* }
used_total=$(( used_total + used ))
available_total=$(( available_total + available ))
done

if [[ $available_total == 0 ]]; then
echo 0
else
bc <<< "scale=4;($used_total/$available_total)*100"
fi

0 comments on commit 429750e

Please sign in to comment.