My requirements for the webhosting monitoring:
- a low resource consumption tool, also OpenSource, (to be run on a VPS with 1vCPU and 512MB RAM)
- capabilities to monitor primary software servers used for webhosting: Apache, NGINX, NodeJS, PostgreSQL, Memcached, Fail2ban;
- system loads and network traffic
Monitorix offer all this and more, to don't forget about email alerts for server thresholds.
At the first look, it seems not so easy to install and configure (especially the Apache and the NGINX stats). But, if documentation are read in correct order, you will have a free webhosting monitoring tool running in your server within minutes.
|
CPU time usage - memory usage |
Here are the installation steps for Debian/Ubuntu, and I'll recommend to use the repository version (I also used that method). Using the repository based version, you will gain more advantages, like automatic updates and automatic installation for dependencies (rrdtool and some Perl libraries)
Now it's time to fine tune your sensors.
The configuration are located here: /etc/monitorix/monitorix.conf but first it's better to take a look at the documentation page to better understand what it's all about. Or start from this monitorix.conf file crafted for webhosting monitoring (replace www.example.com with your own domain name and then pay attention at the Apache and NGINX status monitor, see bellow).
Reload/restart the monitorix daemon after each reconfiguration (sudo systemctl reload monitorix)
To complete the monitor procedure (Apache status, NGINX status and Monitorix reports webpage), few things must be done:
1. Enable Apache status: add/uncomment below line in the Apache https.conf file
LoadModule status_module modules/mod_status.so
2. Enable the NGINX status. To access the NGINX status, the Nginx server must be compiled with HttpStubStatusModule module. Just run
nginx -V 2>&1 | grep -o with-http_stub_status_module
The answer must be "with-http_stub_status_module".
Create necessary monitoring locations in the Nginx configuration for your site
server { ... ... #monitorix location /monitorix { access_log off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:8081/monitorix; allow 127.0.0.1; } #nginx status location /nginx_status { stub_status on; allow 127.0.0.1; allow 1.2.3.4; deny all; } ... ... }
Create necessary monitoring locations in the Apache vhost for your site
<VirtualHost *:8080> ServerName www.example.com ... ... #apache mod_status <Location /apache_status> SetHandler server-status Require ip 127.0.0.1 Require ip ::1 Require ip 1.2.3.4 </Location> </VirtualHost>
Info: the above /monitorix location is configured without no limitation for public access, if you don't feel comfortable with that, just add a simple layer of protection to that location (ip limit or http auth).
Reload/restart the servers (Nginx, Apache, Monitorix) and you are done, you now can access all important webhosting stats at the yourdomain/monitorix url. And of course, if configured so, you will receive all the email alerts based on thresholds.