Mit Monit können Sie eine Website mithilfe eines Nagios-Plugins überwachen

332
Daniel Carrasco Marín

Ich habe eine Webseite, auf der manchmal eine leere Seite mit dem Status 200 angezeigt wird, und ich möchte den Dienst automatisch neu starten, wenn dies geschieht. Um dies zu tun, möchte ich Monit und ein Nagios-Plugin verwenden, mit dem Text auf der Seite durchsucht werden kann. Stattdessen sollte nur der Status überprüft werden. Mein Problem ist jedoch, dass Monit eine lange Zeit benötigt, um zu erkennen, wann die Seite nicht verfügbar ist, und dass der Dienst häufig neu gestartet wird mal auch wenns wieder gut läuft.

Meine Monit-Konfigurationsdatei:

check program nginx with path "/etc/monit/files/check_nginx.sh" every 1 cycle start program = "/etc/init.d/nginx start" stop program = "/etc/init.d/nginx stop" if status != 0 then restart 

Da Monit keine Argumente übergeben darf, verwende ich dieses einfache Skript in bash:

#!/bin/bash /etc/monit/files/check_http -H 127.0.0.1 -w 5,0 -c 10,0 -p 88 exit $? 

Wenn Nagios läuft, wird dies problemlos von Monit erkannt, aber wenn ich den Dämon stoppe, dauerte es etwa zwei Zyklen, um zu erkennen, dass der Server heruntergefahren ist (dies ist akzeptabel, da 2 Minuten dauern). Nachdem das Problem erkannt wurde, führt Monit einen Neustartbefehl ohne Probleme aus:

CEST Sep 26 18:31:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:31:47] info : 'nginx' trying to restart [CEST Sep 26 18:31:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:31:47] info : 'nginx' start: /etc/init.d/nginx 

Das ist in Ordnung, aber das Problem ist, dass nicht erkannt wird, wann es wieder aktiv ist, und der Dienst jedes Mal neu gestartet wird, bis ich den Monit-Dienst deaktiviere:

[CEST Sep 26 18:31:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:31:47] info : 'nginx' trying to restart [CEST Sep 26 18:31:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:31:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:32:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:32:47] info : 'nginx' trying to restart [CEST Sep 26 18:32:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:32:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:33:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:33:47] info : 'nginx' trying to restart [CEST Sep 26 18:33:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:33:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:34:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:34:47] info : 'nginx' trying to restart [CEST Sep 26 18:34:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:34:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:35:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:35:47] info : 'nginx' trying to restart [CEST Sep 26 18:35:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:35:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:36:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:36:47] info : 'nginx' trying to restart [CEST Sep 26 18:36:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:36:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:37:47] error : 'nginx' connect to address localhost and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:37:47] info : 'nginx' trying to restart [CEST Sep 26 18:37:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:37:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:38:47] error : 'nginx' connect to address 127.0.0.1 and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:38:47] info : 'nginx' trying to restart [CEST Sep 26 18:38:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:38:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:39:47] error : 'nginx' connect to address 127.0.0.1 and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:39:47] info : 'nginx' trying to restart [CEST Sep 26 18:39:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:39:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:40:47] info : 'nginx' status succeeded [CEST Sep 26 18:44:47] error : 'nginx' connect to address 127.0.0.1 and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:44:47] info : 'nginx' trying to restart [CEST Sep 26 18:44:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:44:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:45:47] error : 'nginx' connect to address 127.0.0.1 and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:45:47] info : 'nginx' trying to restart [CEST Sep 26 18:45:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:45:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:46:47] error : 'nginx' connect to address 127.0.0.1 and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:46:47] info : 'nginx' trying to restart [CEST Sep 26 18:46:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:46:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:47:47] error : 'nginx' connect to address 127.0.0.1 and port 88: Connection refused HTTP CRITICAL - Unable to open TCP socket  [CEST Sep 26 18:47:47] info : 'nginx' trying to restart [CEST Sep 26 18:47:47] info : 'nginx' stop: /etc/init.d/nginx [CEST Sep 26 18:47:47] info : 'nginx' start: /etc/init.d/nginx [CEST Sep 26 18:48:26] info : Shutting down monit HTTP server [CEST Sep 26 18:48:26] info : monit HTTP server stopped [CEST Sep 26 18:48:26] info : monit daemon with pid [4187] killed 

Ich habe das Bash-Skript getestet, um festzustellen, ob der Dienst wieder verfügbar ist und einwandfrei funktioniert. Monit aktualisiert also den Status nicht oder versucht nicht, den Befehl erneut auszuführen.

Weiß jemand, was passieren kann? Ich weiß nicht, was ich tun soll ...

Vielen Dank!!

1

1 Antwort auf die Frage

0
Daniel Carrasco Marín

Fest. Scheint ein Fehler der Ubuntu-Version zu sein, da ich die neueste Version (5.19.0) heruntergeladen habe und nun auch mit Argumenten gut funktioniert.

Schöne Grüße!!