未验证 提交 e548dd70 编写于 作者: Q QinZuoyan 提交者: GitHub

scripts: improve scripts/pegasus_stat_available.sh (#191)

上级 bcdb11a8
......@@ -2,16 +2,16 @@
PID=$$
if [ $# -ne 2 ]; then
echo "USGAE: $0 <cluster> <filter>"
echo " eg: $0 onebox 2017-07"
if [ $# -lt 2 ]; then
echo "USGAE: $0 <cluster> <filter1> [<filter2> ...]"
echo " eg: $0 onebox 2017-07 2017-08 2017-09"
echo
echo "Result: <cluster> <filter> <day_count> <available>"
echo "Result: <cluster> <serve_days> <available>"
exit 1
fi
cluster=$1
filter=$2
shift
pwd="$( cd "$( dirname "$0" )" && pwd )"
shell_dir="$( cd $pwd/.. && pwd )"
......@@ -30,25 +30,28 @@ if [ "$detect_table" == "" ]; then
exit 1
fi
result_file="pegasus.stat_available.scan_result"
tmp_file="/tmp/$UID.$PID.pegasus.stat_available.scan"
echo -e "use $detect_table\nhash_scan detect_available_day '' '' -s prefix -y \"$filter\" -o $result_file" | ./run.sh shell -n $cluster &>$tmp_file
scan_ok=`grep 'key-value pairs got' $tmp_file | wc -l`
if [ $scan_ok -ne 1 ]; then
echo "ERROR: scan detect table failed, refer error to $tmp_file"
rm -f $result_file
exit 1
fi
days=`cat $result_file | wc -l`
all_result="pegasus.stat_available.all_result"
rm -f $all_result
for filter in $*; do
result_file="pegasus.stat_available.scan_result.$filter"
tmp_file="/tmp/$UID.$PID.pegasus.stat_available.scan"
echo -e "use $detect_table\nhash_scan detect_available_day '' '' -s prefix -y \"$filter\" -o $result_file" | ./run.sh shell -n $cluster &>$tmp_file
scan_ok=`grep 'key-value pairs got' $tmp_file | wc -l`
if [ $scan_ok -ne 1 ]; then
echo "ERROR: scan detect table failed, refer error to $tmp_file"
rm -f $result_file
exit 1
fi
cat $result_file >>$all_result
done
days=`cat $all_result | wc -l`
if [ $days -eq 0 ]; then
echo "ERROR: no detect data found for filter \"$filter\", refer to $tmp_file"
rm -f $result_file
exit 1
available="0.000000"
else
available=`cat $all_result | grep -o '[0-9]*,[0-9]*,[0-9]*' | awk -F, '{a+=$1;b+=$2}END{printf("%f\n",(double)b/a);}'`
fi
echo "$cluster $days $available"
available=`cat $result_file | grep -o '[0-9]*,[0-9]*,[0-9]*' | awk -F, '{a+=$1;b+=$2}END{printf("%f\n",(double)b/a);}'`
rm -f $result_file
echo "$cluster $filter $days $available"
rm -f pegasus.stat_available.scan_result.* $all_result
rm -f /tmp/$UID.$PID.pegasus.* &>/dev/null
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册