Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Adirael
Forked from clasense4/monit
Created April 28, 2016 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adirael/56b6d89ad3d459dc659c78450d56b6e7 to your computer and use it in GitHub Desktop.
Save Adirael/56b6d89ad3d459dc659c78450d56b6e7 to your computer and use it in GitHub Desktop.
Fresh Install monit from 0 Centos 6.5
#!/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
# location : /etc/init.d/monit
# 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

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

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
sudo chkconfig --levels 235 monit on
vim /etc/monit.conf
# uncomment "include /etc/monit/conf.d/*"
mkdir /etc/monit.d/
vim /etc/monit.d/localhost
service monit start

Configuration (/etc/monit.d/localhost/)

Basic

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

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

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
	if mem usage > 80% for 5 cycles then restart

Laravel Artisan Command

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

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment