Created
October 25, 2014 00:55
-
-
Save cjmatta/8409de7e92e0d5c016e5 to your computer and use it in GitHub Desktop.
MapR checkcomp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# checkcomp - A script to show the relative compressed and uncompressd file sizes on a MapR filesystem. | |
# Chris Matta | |
# cmatta@mapr.com | |
# | |
# Currently broken when a directory has multiple dir children. Need to write a directory walk funciton. | |
set -o nounset | |
set -o errexit | |
SCRIPTNAME=$0; | |
REPORT_GB=0; | |
HADOOP=/usr/bin/hadoop; | |
usage () { | |
echo "Usage: ${SCRIPTNAME}: [-h] <file name or directory name of MapR FS>"; | |
exit 1; | |
} | |
getUncompressed () { | |
echo $($HADOOP mfs -lss $1 | grep -v "^\s" | awk '/\// {total = total + $7}END{print total}') | |
} | |
getCompressed () { | |
blocks=$($HADOOP mfs -lss $1 | grep -v "^\s" | awk '/\// {total = total + $8}END{print total}') | |
echo $(($blocks * 8192)); | |
} | |
humanReadableSize () { | |
# Return the human readable size for a file size given in bytes | |
suffix="b"; | |
size=$1; | |
if [[ $1 -ge 1024 ]] | |
then | |
suffix="K"; | |
size=$(($size/1024)); | |
fi | |
if [[ $1 -ge $((1024 * 1024)) ]] | |
then | |
suffix="M"; | |
size=$(($size/1024)); | |
fi | |
if [[ $1 -ge $((1024 * 1024 * 1024)) ]] | |
then | |
suffix="G"; | |
size=$(($size/1024)); | |
fi | |
echo "${size}${suffix}"; | |
} | |
if [[ $# -eq 0 ]] | |
then | |
usage | |
fi | |
if [[ $# -eq 1 ]] | |
then | |
FILENAME=$1; | |
echo $FILENAME | |
fi | |
if [[ $# -eq 2 ]] | |
then | |
if [[ $1 = "-h" ]] | |
then | |
FILENAME=$2; | |
REPORT_GB=1; | |
else | |
usage | |
fi | |
fi | |
compressed=$(getCompressed $FILENAME); | |
uncompressed=$(getUncompressed $FILENAME); | |
if [[ $REPORT_GB -eq 1 ]] | |
then | |
echo "$(humanReadableSize $compressed) compressed"; | |
echo "$(humanReadableSize $uncompressed) uncompressed"; | |
echo $(humanReadableSize $compressed) / $(humanReadableSize $uncompressed)\($(echo "scale = 2; $compressed * 100 / $uncompressed" | bc)%\) | |
else | |
echo "$compressed compressed"; | |
echo "$uncompressed uncompressed"; | |
echo $compressed / $uncompressed \($(echo "scale = 2; $compressed * 100 / $uncompressed" | bc)%\) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment