Monitor linux web-servers with monit

monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamps changes, checksum changes or size changes.

Monit is controlled via an easy to configure control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions via customizable alert messages. Monit can perform various TCP/IP network checks, protocol checks and can utilize SSL for such checks. Monit provides a http(s) interface and you may use a browser to access the monit program.”[ref] .

How to install in ubuntu 8.10

  • sudo apt-get install monit
  • edit /etc/monit/monitrc and remove comments
    #launch system mon every 2min
    set daemon 120
    #set web interface on port 2812
    set httpd port 2812 and
    # allow localhost and request from IP
    allow localhost
    #request username (admin) and password(monit)
    allow admin:monit
    #check apache
    check process apache with pidfile /usr/local/apache/logs/
    #check mysql service (other server)
    check host myserver with address
    if failed icmp type echo count 3 with timeout 3 seconds then alert
    if failed port 3306 protocol mysql with timeout 15 seconds then alert
    #set alerts via email
    set mailserver
    set alert
  • check the syntax of the previous file with
    sudo monit -t
  • edit /etc/default/monit
  • start deamon !!
    sudo /etc/init.d/monit start
  • call web interface
    use admin and password specified before

Compare Files between two directories recursively – PHP script

In this post I’ll present my PHP class to show differences (file missing or different file date) between files in two directories (recursively).
It’s useful to compare two websites (Example, test and live versioning the same server) and show the differences, much faster than a FTP synchronization, and customizable (size differences instead of time, PHP copy commands with backup etc…).

Example of output:
compare files

How to use:
= new CompareDirs("e:/siti/symfapp/", "e:/siti/symfapp2/");
"{$c->totalFiles} files. {$c->skippedFiles} skipped.
{$c->differencesNotFound} missing.{$c->differencesTime} time differences. ".$c->getHTML();

View the code