Monitorear el servidor http

Monitorear el servidor http

Quiero verificar el estado de salud del servidor web. Si obtuvo respuesta http en 2 minutos, entonces el servidor debería reiniciarse. Estoy usando el siguiente comando para verificar el estado:

curl -s -w "%{time_total}\n" -o /dev/null http://localhost:8080/demo1/employee/hello

Pero ejecuta el bucle infinito y busca una respuesta.

Respuesta1

El siguiente script comprobará el tiempo que tarda la URL y, si es más de 2 minutos, entrará en la condición if. Tienes que poner tu comando de reinicio allí. Duerme durante 60 segundos por cada iteración.

#!/bin/bash

LOG_FILE=/tmp/log.txt

while true
do
    echo "$(date) - Checking the URL is up or not" >> ${LOG_FILE}
    TIME_TAKEN=$(curl -s -w "%{time_total}\n" -o /dev/null http://localhost:8080/demo1/employee/hello)
    if [ "${TIME_TAKEN}" -gt "120" ]
    then
        echo "$(date) - Restart required. Time taken is ${TIME_TAKEN}" >> ${LOG_FILE}
        # your restart command goes here
        echo "$(date) - Successfully restarted" >> ${LOG_FILE}
    fi
    echo "$(date) - Sleep for 60 seconds" >> ${LOG_FILE}
    sleep 60
done

información relacionada