################################################################################
# bench.sh - Hace mediciones de rendimiento de cualquier URL que se le pase
# FIXME: Como se pasa el html a minúsculas para parsear las jpg|gif|png, al
# hacer las peticiones de esos archivos para saber cuanto pesan falla
# porque no están en mayúsculas.
# FIXME: No se muestran las imágenes en CSS, solamente se muestran las html
# FIXME: Comprobar el funcionamiento con subdominios, creo que el "sed" que
# calcula el domainmane falla con subdominios y a la hora de agregar esa
# misma variable a CSS/JS internos lo mismo.
# FIXME: El cuenteo de JS/CSS/IMG no se corresponde con el número de elementos
################################################################################
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Bench #1: Apache Benchmark Tool (1000 requests, 30 clients).
# ------------------------------------------------------------------------------
echo -e "=== Apache Benchmarking -n100 -c10 ==="
${AB} -n100 -c10 -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`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} $i`
echo " (intA)" $i ${TIEMPO} ${TAMANO};
if [[ $i == http* ]]; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} $i`
echo " (ext)" $i ${TIEMPO} ${TAMANO};
TAMANO=`${CURL} -sI http://${DOMAIN}/$i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} http://${DOMAIN}/$i`
echo " (intB) http://${DOMAIN}/$i" ${TIEMPO} ${TAMANO}
echo "CSS: ${NUMCSS} file(s)"
if echo ${i} | grep -q "${DOMAIN}"; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} $i`
echo " (intA)" $i ${TIEMPO} ${TAMANO};
if [[ $i == http* ]]; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} $i`
echo " (ext)" $i ${TIEMPO} ${TAMANO};
TAMANO=`${CURL} -sI http://${DOMAIN}/$i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} http://${DOMAIN}/$i`
echo " (intB) http://${DOMAIN}/$i" ${TIEMPO} ${TAMANO}
echo "IMG: ${NUMIMG} file(s)"
if echo ${i} | grep -q "${DOMAIN}"; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} $i`
echo " (intA)" $i ${TIEMPO} ${TAMANO};
if [[ $i == http* ]]; then
TAMANO=`${CURL} -sI $i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} $i`
echo " (ext)" $i ${TIEMPO} ${TAMANO};
TAMANO=`${CURL} -sI http://${DOMAIN}/$i | grep Content-Length | cut -d ' ' -f 2`
TIEMPO=`${CURL} -o /dev/null -s -w %{time_total} http://${DOMAIN}/$i`
echo " (intB) http://${DOMAIN}/$i" ${TIEMPO} ${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}) ==="