Created
May 17, 2018 22:59
-
-
Save 0xa/158a71b47896824535e2eda588f483a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
total=$1 | |
if [ -z "$total" ]; then | |
echo "usage:" | |
echo " $0 <total>" | |
echo "total:" | |
echo " echo 'select count(*) from statuses;' | su - postgres -c 'psql DBNAME'" | |
exit 1 | |
fi | |
count() { curl -s 'http://127.0.0.1:9200/_stats?pretty' | jq '._all.primaries.docs.count'; } | |
timestamp() { date +"%s"; } | |
start=$(count) | |
start_time=$(timestamp) | |
sleep 3 | |
while [ true ]; do | |
count=$(count) | |
now=$(timestamp) | |
dt=$((now - start_time)) | |
dv=$((count - start)) | |
rate=$((dv/dt*60)) | |
#rate=$(echo "scale=2; $dv / $dt * 60" | bc) | |
progress=$((count * 100 / total)) | |
left=$((total - count)) | |
left_min=$((left / rate % 60)) | |
left_h=$((left / rate / 60)) | |
echo "$progress% ($count/$total) (${dt}s avg: $rate/min) (left: ${left_h}h ${left_min}min)" | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment