Skip to content

Instantly share code, notes, and snippets.

@QAutomatron
Last active August 1, 2016 07:58
Show Gist options
  • Save QAutomatron/00794982023883078f42e257946d32d4 to your computer and use it in GitHub Desktop.
Save QAutomatron/00794982023883078f42e257946d32d4 to your computer and use it in GitHub Desktop.
Calculate average time for browser start at selenium nodes in docker containers filtered by name
#!/bin/bash
REGEX_URL="\[get\: https://mail.ru/"
container_time() {
# echo "Looking in: $OUTPUT"
readarray -t array <<< "$(docker logs "$1" | egrep " INFO - (Executing|Done)\: $REGEX_URL"))"
seconds_total=0
i=0
for ((index=0; index <= ${#array[@]}; index++));
do
if [[ "${array[index]}" == *"Executing:"* && "${array[index+1]}" == *"Done:"* ]]; then
date1=${array[index]}
date2=${array[index+1]}
seconds=$(( ( $(date -ud "${date2% INFO *}" +'%s') - $(date -ud "${date1% INFO *}" +'%s') ) ))
if [[ -z "$2" ]] ; then
echo "$seconds seconds"
fi
# echo $(( ( $(date -ud "${date2% INFO *}" +'%s') - $(date -ud "${date1% INFO *}" +'%s') ) )) seconds
seconds_total=$((seconds_total+seconds))
i=$((i+1))
fi
done
if [[ $i -gt 0 ]] ;
then echo "Average value for $1 is: $((seconds_total / i)) seconds"
else echo "Average value for $1 is: none"
fi
}
node_time() {
for OUTPUT in $(docker ps -q -f name=node)
do
container_time "$OUTPUT" false
done
}
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment