Skip to content

Instantly share code, notes, and snippets.

@Adirael
Forked from clasense4/monit
Created April 28, 2016 11:59

Revisions

  1. @clasense4 clasense4 revised this gist Dec 1, 2014. 2 changed files with 31 additions and 3 deletions.
    1 change: 1 addition & 0 deletions monit.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@ wget http://mmonit.com/monit/dist/binary/5.10/monit-5.10-linux-x64.tar.gz
    tar xfz monit-5.10-linux-x64.tar.gz
    cd monit-5.10
    cp conf/monitrc /etc/monit.conf
    cp bin/monit /usr/local/bin/
    vim /etc/init.d/monit #below
    chmod u+x /etc/init.d/monit
    sudo /sbin/chkconfig --add monit
    33 changes: 30 additions & 3 deletions monit_tricks.md
    Original file line number Diff line number Diff line change
    @@ -9,14 +9,23 @@ set mailserver smtp.gmail.com port 587
    username "username@gmail.com" password "password"
    using tlsv1
    with timeout 30 seconds

    check system domain.tld
    if loadavg (1min) > 4 then alert
    if loadavg (5min) > 3 then alert
    if memory usage > 75% then alert
    if cpu usage (user) > 68% then alert
    if cpu usage (system) > 30% then alert
    if cpu usage (wait) > 20% then alert
    ```
    ## Nginx
    ```bash
    check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"
    if failed port 80 protocol http for 2 cycles then restart
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"
    if failed port 80 protocol http for 2 cycles then restart
    if mem usage > 80% for 5 cycles then restart
    ```
    ## Laravel Artisan Command
    @@ -25,4 +34,22 @@ check process queue
    matching "queue:work"
    start = "/bin/bash -c 'cd /var/www/p2tk-crm && /usr/bin/php artisan queue:work --daemon &'"
    if does not exist then start
    ```
    ## MySQL
    ```bash

    check process mysql
    matching "mysqld"
    start program = "/etc/init.d/mysql start"
    stop program = "/etc/init.d/mysql stop"
    if does not exist then start
    ```
    ## PHP-FPM
    ```bash
    check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
    start program = "/etc/init.d/php-fpm start"
    stop program = "/etc/init.d/php-fpm stop"
    if mem usage > 80% for 5 cycles then restart
    ```
  2. @clasense4 clasense4 revised this gist Dec 1, 2014. 2 changed files with 24 additions and 6 deletions.
    13 changes: 9 additions & 4 deletions monit.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,19 @@
    # Install Monit
    ---

    Follow [`http://clasense4.wordpress.com/2012/08/27/monit-how-to-playing-with-monit/`](http://clasense4.wordpress.com/2012/08/27/monit-how-to-playing-with-monit/) untill you're good

    ```bash
    wget http://mmonit.com/monit/dist/binary/5.10/monit-5.10-linux-x64.tar.gz
    tar xfz monit-5.10-linux-x64.tar.gz
    cd monit-5.10
    cp conf/monitrc /etc/monit.conf
    vim /etc/init.d/monit #below
    chmod u+x /etc/init.d/monit
    sudo /sbin/chkconfig --add monit
    sudo chkconfig --levels 235 monit on
    ```

    Then `monit` should start when the server restart
    vim /etc/monit.conf
    # uncomment "include /etc/monit/conf.d/*"
    mkdir /etc/monit.d/
    vim /etc/monit.d/localhost
    service monit start
    ```
    17 changes: 15 additions & 2 deletions monit_tricks.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,25 @@
    # Nginx
    # Configuration (*/etc/monit.d/localhost/*)

    ## Basic
    ```bash
    set daemon 20 # TIMEOUT 20 Seconds
    set logfile syslog facility log_daemon # LOGGING

    set mailserver smtp.gmail.com port 587
    username "username@gmail.com" password "password"
    using tlsv1
    with timeout 30 seconds
    ```

    ## Nginx
    ```bash
    check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"
    if failed port 80 protocol http for 2 cycles then restart
    ```
    # Laravel Artisan Command
    ## Laravel Artisan Command
    ```bash
    check process queue
    matching "queue:work"
  3. @clasense4 clasense4 revised this gist Nov 28, 2014. 4 changed files with 30 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions Instruction.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    1. Follow http://clasense4.wordpress.com/2012/08/27/monit-how-to-playing-with-monit/ untill you're good
    2. cp conf/monitrc /etc/monit.conf
    3. vim /etc/init.d/monit (below)
    4. chmod u+x /etc/init.d/monit
    5. sudo /sbin/chkconfig --add monit
    6. sudo chkconfig --levels 235 monit on

    Then monit should start when the server restart
    1 change: 1 addition & 0 deletions monit
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@
    # processname: monit
    # config: /etc/monit.conf
    # pidfile: /var/run/monit.pid
    # location : /etc/init.d/monit
    # Short-Description: Monit is a system monitor

    # Source function library.
    14 changes: 14 additions & 0 deletions monit.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # Install Monit
    ---

    Follow [`http://clasense4.wordpress.com/2012/08/27/monit-how-to-playing-with-monit/`](http://clasense4.wordpress.com/2012/08/27/monit-how-to-playing-with-monit/) untill you're good

    ```bash
    cp conf/monitrc /etc/monit.conf
    vim /etc/init.d/monit #below
    chmod u+x /etc/init.d/monit
    sudo /sbin/chkconfig --add monit
    sudo chkconfig --levels 235 monit on
    ```

    Then `monit` should start when the server restart
    15 changes: 15 additions & 0 deletions monit_tricks.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # Nginx
    ```bash
    check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"
    if failed port 80 protocol http for 2 cycles then restart
    ```
    # Laravel Artisan Command
    ```bash
    check process queue
    matching "queue:work"
    start = "/bin/bash -c 'cd /var/www/p2tk-crm && /usr/bin/php artisan queue:work --daemon &'"
    if does not exist then start
    ```
  4. @clasense4 clasense4 renamed this gist Oct 7, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @clasense4 clasense4 created this gist Feb 16, 2014.
    8 changes: 8 additions & 0 deletions Instruction
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    1. Follow http://clasense4.wordpress.com/2012/08/27/monit-how-to-playing-with-monit/ untill you're good
    2. cp conf/monitrc /etc/monit.conf
    3. vim /etc/init.d/monit (below)
    4. chmod u+x /etc/init.d/monit
    5. sudo /sbin/chkconfig --add monit
    6. sudo chkconfig --levels 235 monit on

    Then monit should start when the server restart
    86 changes: 86 additions & 0 deletions monit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    #!/bin/bash
    #
    # Init file for Monit system monitor
    # Written by Stewart Adam <s.adam@diffingo.com>
    # based on script by Dag Wieers <dag@wieers.com>.
    #
    # chkconfig: - 98 02
    # description: Utility for monitoring services on a Unix system
    #
    # processname: monit
    # config: /etc/monit.conf
    # pidfile: /var/run/monit.pid
    # Short-Description: Monit is a system monitor

    # Source function library.
    . /etc/init.d/functions

    ### Default variables
    CONFIG="/etc/monit.conf"
    pidfile="/var/run/monit.pid"
    prog="monit"

    # Check if requirements are met
    [ -x /usr/local/bin/monit ] || exit 1
    [ -r "$CONFIG" ] || exit 1

    RETVAL=0

    start() {
    echo -n $"Starting $prog: "
    /usr/local/bin/monit -c "$CONFIG"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
    }

    stop() {
    echo -n $"Shutting down $prog: "
    killproc -p ${pidfile}
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
    }

    restart() {
    stop
    start
    }

    reload() {
    echo -n $"Reloading $prog: "
    /usr/local/bin/monit -c "$CONFIG" reload
    RETVAL=$?
    echo
    return $RETVAL
    }

    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    restart
    ;;
    reload)
    reload
    ;;
    condrestart)
    [ -e /var/lock/subsys/$prog ] && restart
    RETVAL=$?
    ;;
    status)
    status $prog
    RETVAL=$?
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
    RETVAL=1
    esac

    exit $RETVAL