Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
monit [2016/05/31 16:17]
yassine chaouche [Configuring the HTTP port for the monit web interface]
monit [2019/08/21 12:50] (current)
yassine chaouche
Line 10: Line 10:
 For example, your script might say : try to get a webpage from http://​my.web.app,​ if you fail 3 times in a row, then restart the web application with this command : /​etc/​init.d/​my.web.app restart. For example, your script might say : try to get a webpage from http://​my.web.app,​ if you fail 3 times in a row, then restart the web application with this command : /​etc/​init.d/​my.web.app restart.
  
-If you are a sysadmin, just put your script in /​etc/​monitrc+If you are a sysadmin, just put your script ​somewhere ​in /etc/​monit/​conf.d/​ because that directory is read by monit (you will find an ''​include /​etc/​monit/​conf.d/​*''​ line in ''/​etc/​monit/monitrc''​).
  
 You can test your script with the -t option like this :  You can test your script with the -t option like this : 
Line 58: Line 58:
 </​code>​ </​code>​
  
-This is used to restart ​the program.+This line adds a new check to monit, based on pid files. Next, you can specify what actions to do when a specific test fails (or passes). 
 +If monit tells you that it can't find any process named "​infomaniak"​ then make sure the path to the pid file is correct and that it contains ​the real pid of infomaniak (for example with ''​ps $(</​var/​run/​infomaniak.pid)''​)
  
-The most interesting part is of course tests.+=== Tests and example script explained ===
  
-=== Tests ===+Read monit'​s documentation website, [[https://​mmonit.com/​monit/​documentation/​monit.html#​SERVICE-TESTS|Service ​Tests section]] 
 +<​code>​ 
 +root@app-server[192.168.100.83] ~ # nl /​etc/​monit/​conf.d/​infomaniak 
 +     ​1 ​ check process infomaniak pidfile /​var/​run/​infomniak.pid 
 +     ​2 ​       start   "/​etc/​init.d/​infomaniak start"​ 
 +     ​3 ​       stop    ​"/​etc/​init.d/​infomaniak stop"​ 
 +     ​4 ​       restart ​"/​etc/​init.d/​infomaniak restart"​
  
-Too many tests available, read them all over at monit'​s documentation site, [[https://​mmonit.com/​monit/​documentation/​monit.html#​SERVICE-TESTS|Service Tests section]]+     ​5 ​       if failed 
 +     ​6 ​          host audio-mon.eprs.dz 
 +     ​7 ​          port 8000 
 +     ​8 ​          ​protocol HTTP 
 +     ​9 ​          with timeout 60 seconds 
 +    10        then 
 +    11          restart 
 +root@app-server[192.168.100.83~ #
  
-<​code>​ 
-CHECK PROCESS infomaniak PIDFILE /​var/​run/​infomaniak.pid 
-    restart = /​etc/​init.d/​infomaniak restart 
-    IF FAILED http://​audio-mon.eprs.dz ​ 
-      PORT 8000  
-      PROTOCOL HTTP  ​ 
-      TIMEOUT 300  
-    THEN  
-      ALERT 
 </​code>​ </​code>​
  
 +  - line      1 : A new CHECK is added. It is about checking a process, by looking at its pidfile.
 +  - lines   2-4 : list of commands do start/stop the monitored process. Note that they must be enclosed in double quotes.
 +  - line      5 : this is a failure test
 +  - lines   6-9 : these are the arguments of the test
 +  - lines    11 : this is the action to do when the test passes (remember we are testing for failure, so the test passes when there is a failure in getting an HTTP response from audio-mon.eprs.dz:​8000 after a 60 seconds period).
 +
 +==== Configuring Monit ====
 +Following is a minimal list of most useful configs to do in the /​etc/​monit/​monitrc configuration file. This file is used to configure monit itself. ​
  
-==== Launching Monit in daemon mode ====+=== Launching Monit in daemon mode ===
  
-Still in the configuration file, use the SET keyword. ​+This is how to configure monit to run in daemon mode :
  
 <​code>​ <​code>​
Line 87: Line 100:
 </​code>​ </​code>​
  
-This tells monit to set its polling cycle to 60 seconds and acknowledges it that it will be run from initd (/​etc/​init.d/​monit),​ which is better than launching from the command line (because you then can run the service at boot time with rc.d)+It tells monit to set its polling cycle to 60 seconds and acknowledges it that it will be run from initd (/​etc/​init.d/​monit),​ which is better than launching from the command line (because you then can run the service at boot time with rc.d)
  
-==== Configuring the HTTP port for the monit web interface ​====+=== Configuring the HTTP port for the monit web interface ===
 <​code>​ <​code>​
 SET HTTPD PORT 8001 ALLOW user:pass SET HTTPD PORT 8001 ALLOW user:pass
Line 95: Line 108:
  
 You must put an ALLOW keyword, otherwise it won't work.  You must put an ALLOW keyword, otherwise it won't work. 
-==== Sending alerts when something goes wrong ====+=== Sending alerts when something goes wrong ===
  
 Use '''​SET ALERT''',​ either globally or by '''​check'''​ line Use '''​SET ALERT''',​ either globally or by '''​check'''​ line

QR Code
QR Code The concept of cycles (generated for current page)