Monitorar servidor http

Monitorar servidor http

Quero verificar o status de integridade do servidor web. Se obtiver resposta http em 2 minutos, o servidor deverá reiniciar. Estou usando o comando abaixo para verificar o status –

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

Mas executa o loop infinito e verifica uma resposta.

Responder1

O script abaixo irá verificar o tempo que a url leva e se for superior a 2 minutos, ele irá dentro da condição if. você tem que colocar seu comando de reinicialização lá. Ele dorme por 60 segundos para cada iteração

#!/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

informação relacionada