Monit provides autonomous monitoring (cli and web) on the system as well as an agent that is calling for M/Monit.

Either use your system's packages, third-parity binaries or the source (./configure --without-pam on Slackware). For Windows, there is monit-windows-agent to try out.

Debian system,

apt install monit netcat ksh
#  exim4 | postfix | mail-transport-agent sysvinit-core
cd /etc/monit/

Redhat/EPEL system,

yum install monit
cd /etc/

Slackware,

sbopkg -i monit
cd /etc/

NetBSD,

pkg_add monit
ln -s /usr/pkg/etc/monit ~/

And then,

#nmap -p 8080 mmonit
nc -z -v -w5 mmonit 8080

mv monitrc monitrc.dist
sed '/^[[:space:]]*$/d; /^[[:space:]]*#/d' monitrc.dist > monitrc
chmod 600 monitrc

ifconfig | grep ^[[:alpha:]] | cut -f1 -d:
for netif in `ifconfig | grep ^[[:alpha:]] | cut -f1 -d:`; do
    echo check network $netif with interface $netif
done; unset netif; for fs in `df -P | egrep '^/dev/sda|^/dev/xbd|^/dev/root' | awk '{print $NF}'`; do
    echo check filesystem `echo $fs | sed 's#/#_#g'` with path /
done; unset fs

vi monitrc

#set daemon 60
set daemon 30

#set mmonit http://monit:PASSWORD@mmonit:8080/collector
set mmonit https://monit:PASSWORD@$mmonit/collector

(copy/paste netifs)
(copy/paste fses)

Debian systems,

systemctl reload monit
systemctl status monit

Redhat systems,

systemctl start monit
systemctl enable monit
systemctl status monit

Slackware,

vi /etc/rc.local

#self verbose
#from source: /usr/local/bin/monit
/usr/bin/monit

Troubleshooting

Eventually check that the monit host resolves, responds, and that the mmonit service is reachable, preferably on port 443,

mmonit=mmonit.example.local
ping -c1 $mmonit
nmap -p 80,443 $mmonit

For network monitoring, identify what network interface you are using,

    netifs=`ifconfig | grep ^[[:alpha:]] | egrep -v ^lo | awk '{print $1}'`
    echo $conf
echo $netifs

for netif in $netifs; do cat >> $conf < 90% then alert
        if total upload > 1 GB in last hour then alert
EOF
done; unset netif

unset netifs

Check how many CPUs you have,

grep ^proc /proc/cpuinfo | wc -l

Check your short hostname and FQDN,

#hostname
#hostname --long

The default CPU info that shows up is wait. I like that so I do not tweak that.

#cat >> $conf <<-EOF
#
#check system HOSTNAME
#       if loadavg (15min) > 4 then alert
#       if memory usage > 90% then alert
#       if swap usage > 5% then alert
#       if cpu usage (wait) > 10% then alert
#       group system_resources
#EOF

Eventually check that your smtp relay responds and that your email setup is in place.

hostmaster=hostmaster@example.com
smarthost=smarthost.example.local
nmap -p 25 $smarthost
telnet $smarthost 25
quit

Mail alerts setup,

set mailserver $smarthost, localhost
set alert $hostmaster

set mail-format {
    from: $hostmaster
    subject: Monit alert -- $EVENT $SERVICE
    message: $EVENT Service $SERVICE

    Date:        $DATE
    Action:      $ACTION
    Host:        $HOST
    Description: $DESCRIPTION

    -- 
    Monit http://$HOST:2812/
    M/Monit https://$mmonit/
}

old ubuntu 14

apt install git build-essential libtool automake
git clone https://bitbucket.org/tildeslash/monit.git
cd monit/
./bootstrap

apt install byacc flex zlib1g-dev libssl-dev
./configure --without-pam
make
#apt purge monit
#apt autoremove
make install
cp ~/monit/monitrc /etc/
ln -s /etc/monitrc ~/

vi /etc/rc.local

#self verbose
/usr/local/bin/monit

Workstation

Prepare some dummy key,

#apt install ssl-cert
#/var/lib/dpkg/info/ssl-cert.postinst
ls -lhF /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/private/ssl-cert-snakeoil.key
chmod 400 /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/private/ssl-cert-snakeoil.key

and add this to monitrc (eventuall enable ssl),

set httpd port 2812
        signature disable
        #ssl enable
        #pemfile /etc/ssl/certs/ssl-cert-snakeoil.pem
        allow localhost        # allow localhost to connect to the server and
        allow admin:monit      # require user 'admin' with password 'monit'

Monitoring Daemons

Setup additional services'monitoring e.g.,

check process mongod with pidfile /var/run/mongodb/mongod.pid
    if cpu > 60% for 2 cycles then alert
    #if totalmem > 1 GB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then alert
    group server

Ready to go

Start the daemon and enable it at boot time,

    #Ubuntu
    #already started & enabled while pkg installation
    systemctl restart monit

#RHEL6,7
service monit restart
chkconfig monit on

#binaries on Debian
/usr/local/monit/bin/monit stop all
/usr/local/monit/bin/monit start all
vi /etc/rc.local

echo -n starting monit...
/usr/local/monit/bin/monit start all && echo done

You should now see the added host within the M/Monit interface.

References