This website uses Google Analytics and Advertising cookies, used to generate statistical data on how visitors uses this website (with IP anonymization) and to deliver personalized ads based on user prior visits to this website or other websites. [read more]
These cookies are disabled by default until your Accept/Reject Consent.
The Consent can be changed at any time by accesing the ePrivacy button located at the bottom of every page. Enjoy your visit!



Monitorix: a lightweight solution to monitor webhosting

In my searches for an opensource solution to monitor the webhosting server, I found a few, and the Monitorix project was the chosen one, because Monitorix provided me exactly what I was looking for.

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
The Monitorix monitoring tool can be installed in a variety of UNIX based OS's, for example, in a Debian/Ubuntu environment
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
and check if you have that module installed.

The answer must be "with-http_stub_status_module".
If yes, you can continue with the rest of configurations.

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>

Replace the 1.2.3.4 IP with your server public IP.
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.

Final words

As Monitorix is based on RRDtool, the RRDtool db files (.rrd) can be used stand-alone in custom php projects, because those files can be accessed and processed using php and even with javascript. That way, the graphs can be draw using the javascript Flot plotting library (http://www.flotcharts.org/).

label_outline

Share this post on your favorite networks.
© Copyright 2017 b247.eu.org | Just another information technology blog - All Rights Reserved