Skip to main content

System/ Process Monitoring in Linux using MONIT


Install and Configure Monit
sudo apt-get install monit
usudo chmod 700 /etc/monit/monitrc
telnet localhost 2812
sudo ufw allow 2812

Sample MONIT Configuration
username@ServerName:/etc/monit$ sudo cat monitrc
set daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: monit@ServerName.localnet }
set alert username.shah@cw.com
set httpd port 2812 and
#     SSL ENABLE
#     PEMFILE  /etc/monit/monit.pem
    allow admin:edgeadmin

check system edge.localnet
    if loadavg (1min) > 4 then alert
    if loadavg (5min) > 2 then alert
    if memory usage > 70% then alert
    if swap usage > 20% then alert
    if cpu usage (user) > 70% then alert
    if cpu usage (system) > 30% then alert
    if cpu usage (wait) > 20% then alert

# SENDMAIL
check process sendmail with pidfile /var/run/sendmail/mta/sendmail.pid
  group services
  start program "/etc/init.d/sendmail start"
  stop program "/etc/init.d/sendmail stop"
  if failed port 25 protocol smtp then restart
  if 5 restarts within 5 cycles then timeout

# SSHD
check process sshd with pidfile /var/run/sshd.pid
  group system
  start program  "/sbin/start ssh"
  stop program  "/sbin/stop ssh"
  if failed port 22 protocol ssh then restart
  if 5 restarts within 5 cycles then timeout

# ORACLE XE
check process oracle with pidfile /var/run/oracle-xe.pid
  group services
  start program "/etc/init.d/oracle-xe start"
  stop program "/etc/init.d/oracle-xe stop"
  if cpu usage > 23% for 5 cycles then restart
  if failed host ServerName.localnet port 1521 timeout 60 seconds then restart
  if failed host ServerName.localnet port 8080 timeout 120 seconds then restart
  if 5 restarts within 5 cycles then timeout

# VNC
check process Xvnc4 with pidfile "/home/username/.vnc/ServerName.localnet:1.pid"

  start program "/sbin/initctl start vncserve"
  stop program "/sbin/initctl stop vncserve"
  if failed port 5901 then restart
  if 5 restarts within 5 cycles then timeout

# VNC
#check process Xvnc4 with pidfile "/home/username/.vnc/ServerName.localnet:1.pid"
#   start program "/home/username/vnc.sh"
#   stop program "/home/username/vnc-kill.sh"
#   if failed port 5901 then restart
#   if 5 restarts within 5 cycles then timeout

# SMBD
#check process smbd with pidfile /var/run/samba/smbd.pid
#   group system
#   start program  "/sbin/start smbd"
#   stop program  "/sbin/stop smbd"
#   if failed port 139 then start
#   if 5 restarts within 5 cycles then timeout

# SKYPEVNC
#check process Xvnc4 with pidfile "/home/username/.vnc/servername\:2.pid"
#   start program "/etc/skype-start.sh"
#   stop program "/etc/skype-stop.sh"
#   if failed port 5902 then start
#   if 5 restarts within 5 cycles then timeout

# DNS SERVER
#check process named with pidfile /var/run/bind/run/named.pid
#   group services
#   start program  "/etc/init.d/bind9 start"
#   stop program  "/etc/init.d/bind9 stop"
#   if failed host 127.0.0.1 port 53 type tcp protocol dns then alert
#   if failed host 127.0.0.1 port 53 type udp protocol dns then alert
#   if 5 restarts within 5 cycles then timeout

# MYSQL
#check process mysql with pidfile /var/run/mysqld/mysqld.pid
#   group services
#   start program = "/etc/init.d/mysql start"
#   stop program = "/etc/init.d/mysql stop"
#   if failed host 127.0.0.1 port 3306 then restart
#   if 5 restarts within 5 cycles then timeout

# APACHE
#check process apache with pidfile /var/run/apache2.pid
#   group services
#   start program = "/etc/init.d/apache2 start"
#   stop program  = "/etc/init.d/apache2 stop"
#   if failed host admin.hosting.example.com port 80 protocol http
#      and request "/tools/monin_test_file" then restart
#   if cpu is greater than 60% for 2 cycles then alert
#   if cpu > 90% for 5 cycles then restart
#   if totalmem > 500 MB for 5 cycles then restart
#   if children > 250 then restart
#   if loadavg(5min) greater than 10 for 8 cycles then stop
#   if 3 restarts within 5 cycles then timeout

# POSTFIX
#check process postfix with pidfile /var/spool/postfix/pid/master.pid
#   group services
#   start program = "/etc/init.d/postfix start"
#   stop  program = "/etc/init.d/postfix stop"
#   if failed port 25 protocol smtp then restart
#   if 5 restarts within 5 cycles then timeout

# ISPCP_DAEMON
#check process ispcp_daemon with pidfile /var/run/ispcp-daemon.pid
#   group services
#   start program = "/etc/init.d/ispcp_daemon start"
#   stop  program = "/etc/init.d/ispcp_daemon stop"
## If you active this, your /var/log/daemon will grow every minute,
## so it's not recomended unless you don't want to trust only in .pid
##   if failed port 9876 then restart
#   if 5 restarts within 5 cycles then timeout

Sample VNC Server Startup Script

username@ServerName:~$ cat /home/username/vnc.sh
#!/bin/bash
su -l username -c “/usr/bin/vnc4server :1 -name "my Server Name" -geometry 1280x730”

Sample VNC Server Stop Script

username@ServerName:~$ cat /home/username/vnc-kill.sh
#!/bin/bash
/usr/bin/vncserver -kill :1

Sample Script to create a PID for a non-pid type process
username@ServerName:~$ sudo cat /etc/monit/oracle-xe-pid.sh
#!/bin/bash

pmon=`ps -ef | egrep pmon_XE'\>' | grep -v grep| awk '{ print $2 }'`

if [ "$pmon" = "" ];
then
   rm /var/run/oracle-xe.pid
else
       echo $pmon > /var/run/oracle-xe.pid
fi

Sample Cron to check, create and update PID every minute

username@ServerName:~$ sudo crontab -l
* * * * * /etc/monit/oracle-xe-pid.sh

Popular posts from this blog

TrueCrypt on macOS X Mojave 10.14

If you have updated your macOS recently to Mojave otherwise known as verison 10.14 you may not be able to install the last version of Truecrypt in order to access your old volumes encrypted with Truecrypt software. This article will guide you to get this working on your MacOS v10.14 (Mjoave).

Download the package from https://truecrypt.ch/downloads/ or https://www.truecrypt71a.com/downloads/.
Find downloaded package using Finder in your HDD/Users/username/Downloads folder and will look like TrueCrypt 7.1a Mac OS X.dmg.

Open file location in Finder and open or double click on TrueCrypt 7.1a Mac OS X.dmg. This will mount Truecrypt 7.1a and will have Truecrypt 7.1a.mpkg in it.

Drag the package TrueCrypt 7.1a.mpkg and drop in your Downloads folder.

From Locations in Finder you can eject your TrueCrypt mount.

Now go to your Downloads location, find the file TrueCrypt 7.1a.mpkg, right click and select Show Package Contents. Find the file Contents/distribution.dist and open with your favourite edi…

Starting with Python

New to Python, don't feel behind and get started now, it is never too late.
Here we have some useful links you will need to get you going.
https://realpython.com/start-here/
https://www.anaconda.com/distribution/
https://jupyterlab.readthedocs.io/en/stable/

CoVid-19 Statistics and Charts

Statistics based on some specific metrics are listed below. The data is based on daily information from Worldometer and updated manually. Charts will update automatically.

Please use links below to get to individual charts and feel free to bookmark this page but do not bookmark direct chart link as it may change. These charts compare statistics for countries including China, Italy, UK, US, Pakistan & India.
(Does not work in Safari Mobile)

Please click on links below for specific chart, more to come.


Death Doubling RateChart showing death rate doubling in x number of days.


Survival RateThis chart shows trend of patients successfully recovered vs total closed cases.
Death rate comparisonComparison of deaths per cases every day showing trend comparison and days behind.
Cases reportedNo of cases reported, how far they are behind each other and trend. Deaths reported No of deaths reported with trend comparison between three countries.

The data for these charts is extracted directly from John Ho…