• Measure your server performance Monit-Graph

At Dream Conception we are focused in entrepreneurship, and startups. Also we have a high degree of technical experience which we use to make our daily life easier. For most startups open source software is vital. Without open source it would have been impossible to create the technological startups we see today.

Introducing Monit-Graph: Your server performance monitoring system

At Dream Conception we have a lot of servers, so it is critical for us to receive notifications about abnormalities in the performance. Just as critical is it to be able to see the progress up to that point, to pin-point what is going wrong. That is why we have built the PHP-based tool, Monit-Graph.

How to get e-mail notifications about critical server performance with Monit

Monit is a great free open source tool. It is included in APT. Monit can monitor processes, files, and directories, and you can configure it to alert at certain trigger points. It can even be programmed to do automatic maintenance.

The setup of Monit is very straight forward. The following procedure is for Ubuntu, but many distributions should have similar or identical steps. If you already have Monit set up, just make sure that it’s httpd server is running, and scroll down to the Monit-Graph setup.

  1. Install Monit

    # sudo apt-get update
    # sudo apt-get install monit
    
  2. Edit configuration file for Monit

    # sudo vi /etc/monit/monitrc
    

    The below parameters are the important ones. Please adjust them to your specific system setup. myemail@example.tld should be changed to your email adress.

    set idfile /var/run/monit-id
    set statefile /var/run/monit-state
    set daemon 60
    set logfile /var/log/monit.log
    set mailserver localhost
    set mail-format { from: monit@example.tld }
    set alert myemail@example.tld   # receive all alerts
    set httpd port 2812 and use the address XX.XX.XX.XX      # Remove "and use the address XX.XX.XX.XX", if not bind to specific IP
    ssl enable                      # Enabling SSL
    pemfile /etc/ssl/monit.pem      # The PEM file
    signature disable               # No server signature to send
    allow mylogin:"mypassword"      # Login
    

    Note: Remember to allow httpd to run, or else Monit-Graph cannot start graphing the server performance.

  3. Add services to Monit

    You will need to add configuration files for which services you wish to monitor. You should add these files to the /etc/monit/conf.d/ directory. You can find examples at the Github page for apache, postfix, and the server as a whole. It should give you plenty idea of how it works, and you can just copy-paste them.After setting up the configurations files, you need to verify that the configurations are good by running:

    # monit -t

    If there is any errors, go back, and modify the configurations files until it reports OK.

  4. Restart/start Monit

    The final step is to do a simple restart/start of Monit. Just run the below, and you will be receiving e-mails whenever something critical happens (whatever your configuration files are based to trigger on).

    # service monit restart

    Graph Detail in Monit-Graph

Final step: Graphing the server performance

This is the second part, and where Monit-Graph get’s into the picture. Monit-Graph is based on PHP and are using Google Charts to display graphical statistics.

Download the zip of Monit-Graph, unpack it, and upload it to your server, in whatever directory you wish use to access the statistics.

Follow these steps:

  1. Change permissions (chmod) for the ./data directory to 777.
  2. Change permissions (chmod) for ./data/index.php to 644.
  3. Modify ./config.php to match your setup of monit as well as needs of graphing.
  4. Setup a crontab job to run cron.php every minute. Example: * php /path/to/monit/cron.php >>/var/log/monit-graph.log
  5. Verify after a few minutes of running that the logging happens. You can check the php error log if there seams to be something wrong.
    One last part you wish to do is to password protect the directory. This can be done through .htaccess.

Now you can access the statistics through your webbrowser! You are now able to select specific processes to monitor and it has a memory leak, or other issues. Also you can simply graph the whole servers usage to find e.g. peak hours.

The Author

Dan Schultzer is an active experienced entrepreneur, starting the Being Proactive groups, Dream Conception organization, among other things. You can find him at twitter

Like this post? More from Dan Schultzer

Comments? We would love to hear from you, write us at @dreamconception.