Website Monitoring (and all things monitoring)

There are many tools and services to help you monitor websites and applications. The purpose of this page is to give you options.

Monit

The simplest, easiest, off-the-shelf solution is Monit. Here is a demonstration. The iDempiere installation script includes Monit installation and sample configuration instructions.

Monitoring Java Heap

jcmd is an example command line tool to monitor java heap usage. jcmd is installed with Java. Here are example commands: Here are options to be able to perform automatic heap dumps when an out of memory error occurs: Here is a script that you can use to write the free heap to a file. Once the free heap value is in a file, you can use any monitoring tool to read the value from the file. Note that you should run this script with 'sudo -u idempiere'. Note: updated scripts located here.
pid=$(ps -aux | grep -v root | grep '/usr/lib/jvm/java-11-openjdk-amd64/bin/java -Xms' | awk '{print $2}')
heapused=`jcmd $pid GC.heap_info | grep garbage-first | awk '{print $6}' | cut -d 'K' -f1`
totalheap=`jcmd $pid GC.heap_info | grep garbage-first | awk '{print $4}' | cut -d 'K' -f1`
heapfree=$(($totalheap - $heapused))
heapfreeinmb=$(($heapfree/1024))

DIY Approach

There are times when it is easier to write your own solution that learn a new tool. The next couple of sections give you the basics of how to monitor a web page.

DIY Prep

The scripts in this page depend on the following: Create your log directory:
mkdir /home/ubuntu/log
Create your script directory:
mkdir /home/ubuntu/script
Install the necessary tools to send email when your site goes down. Chose “unconfigured” when prompted. Follow the configuration details listed here.
sudo apt-get install -y mailutils ssmtp
Add the following lines to /etc/ssmtp/ssmtp.conf
AuthUser=<user>@gmail.com
AuthPass=Your-Gmail-Password
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

DIY Script

Copy the below script to a file named /home/ubuntu/script/webMonitor.sh. The below Linux script iterates across an array of sites/phrases to check for the existence of a specific phrase in each site.
#!/bin/bash

#Add all your sites in the below list/array.
#Add each site on a new line.
#Separate the URL from the phrase with a "pipe" or vertical line.
array=("54.204.8.228|Online Book"
        "54.243.158.129|Open Source ERP Academy"
        "www.chuckboecking.com|Open Source ERP Academy")

LOG="/home/ubuntu/log/webMonitor_`date +%Y%m%d`.log"

for ix in ${!array[*]}
do
    SITE=$(echo "${array[$ix]}" | cut -d'|' -f1)
    #echo "Site="$SITE
    PHRASE=$(echo "${array[$ix]}" | cut -d'|' -f1 --complement)
    #echo "Phrase="$PHRASE

    RESULT=$(curl -s -f $SITE  | grep -m 1 -o "$PHRASE")
    #echo "Result="$RESULT

    if [[ "$RESULT" == "$PHRASE" ]]
    then
            echo "$SITE is up at `date +%Y%m%d:%r`" >> $LOG
    else
            echo "$SITE is DOWN!!" | mail -s "$SITE is DOWN" chuck@chuboe.com
            echo "$SITE is DOWN!! at `date +%Y%m%d:%r`" >> $LOG
    fi
done
exit

DIY Crontab - Automated Execution

To execute the above script on a timer, open your user's crontab:
crontab -e
Add the following lines to the bottom. Note the /dev/null tells cron to ignore any script output.
# Monitor sites every 20 minutes
*/20 * * * * /home/ubuntu/script/webMonitor.sh &> /dev/null

Monitoring Processes

Here is a link to help you monitor a local process.

Monitoring Disk Space

Here is a link to help you monitor disk space.