################################################################################
# bench.sh - Hace mediciones de rendimiento de cualquier URL que se le pase
################################################################################
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Bench #1: Apache Benchmark Tool (1000 requests, 30 clients).
# ------------------------------------------------------------------------------
echo -e "=== Apache Benchmarking -n1000 -c30 ==="
${AB} -n1000 -c30 -q -k -H 'Accept-Encoding: gzip,deflate' $URL | grep 'per second' | awk '{print "Peticiones por segundo: " $4 }'
# ------------------------------------------------------------------------------
# Bench #2: Curl, time to connect, transfer and total time of the request.
# ------------------------------------------------------------------------------
echo -e "=== Tiempos de conexión ==="
${CURL} -o /dev/null -s -w " Connect: "%{time_connect}"\n Transfer: "%{time_starttransfer}"\n Total: "%{time_total}"\n" $URL
# ------------------------------------------------------------------------------
# Bench #3: Wget plain and gzipped pettition.
# ------------------------------------------------------------------------------
echo -e "=== Plano y gzip ==="
${WGET} -q -O gzip --header="Accept-Encoding: gzip" $URL
# ------------------------------------------------------------------------------
# Bench #4: Nº of javascript and css files
# ------------------------------------------------------------------------------
echo -e "=== Javascript/CSS info ==="
cat plano | awk '{print tolower($0)}' | sed s/src/\\nsrc/g | sed s/href/\\nhref/g | sed s/\'/\"/g > plano2
JS=`cat plano2 | grep -P "src=[^*]*\.js" | awk -F 'src="' '{ print $2 }' | awk -F '"' '{ print $1 }' | sort | uniq`
CSS=`cat plano2 | grep -P "href=[^*]*\.css" | awk -F 'href="' '{ print $2 }' | awk -F '"' '{ print $1 }' | sort | uniq`
IMG=`cat plano2 | grep -P "src=[^*]*\.(jpg|gif|png)" | awk -F 'src="' '{ print $2 }' | awk -F '"' '{ print $1 }' | sort | uniq`
NUMJS=`cat plano2 | grep -P "src=[^*]*\.js" | sort | uniq | wc -l`
NUMCSS=`cat plano2 | grep -P "href=[^*]*\.css" | sort | uniq | wc -l`
NUMIMG=`cat plano2 | grep -P "src=[^*]*\.(jpg|gif|png)" | sort | uniq | wc -l`
echo "JS: ${NUMJS} file(s)"
if echo ${i} | grep -q "${DOMAIN}"; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
echo " (int)" $i ${TAMANO};
if [[ $i == http* ]]; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
echo " (ext)" $i ${TAMANO};
TAMANO=`${CURL} -sI http://${DOMAIN}/$i | grep Content-Length | cut -d ' ' -f 2`
echo " (int)" http://${DOMAIN}/$i $TAMANO;
echo "CSS: ${NUMCSS} file(s)"
if echo ${i} | grep -q "${DOMAIN}"; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
echo " (int)" $i $TAMANO;
if [[ $i == http* ]]; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
echo " (ext)" $i $TAMANO;
TAMANO=`${CURL} -sI http://${DOMAIN}/$i | grep Content-Length | cut -d ' ' -f 2`
echo " (int)" http://${DOMAIN}/$i $TAMANO;
echo "IMG: ${NUMIMG} file(s)"
if echo ${i} | grep -q "${DOMAIN}"; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
echo " (int)" $i $TAMANO;
if [[ $i == http* ]]; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
echo " (ext)" $i $TAMANO;
TAMANO=`${CURL} -sI http://${DOMAIN}/$i | grep Content-Length | cut -d ' ' -f 2`
echo " (int)" http://${DOMAIN}/$i $TAMANO;
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
echo -e "[bench.sh] - Hace mediciones de rendimiento de cualquier URL que se le pase"
echo -e "como parámetro. Está basado en ab, curl y wget. Los resultados pueden variar"
echo -e "dependiendo de la latencia de red, el estado del host, etc..."
echo -e "\nModo de empleo: bench.sh [OPCIONES]"
echo -e "\t--url o -u http://www.domain.com/test-url/\tPetición a analizar"
echo -e "\t--help o -h\t\t\t\t\tPara ver este menú de ayuda\n"
echo -e "\t $ isp.sh -u http://www.domain.com/"
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
--help|-h) showHelp; exit 0;;
DOMAIN=`echo ${URL} | sed -e "s/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/"`;
echo -e "=== Testing ${URL} (${DOMAIN}) ==="