Alternative to Application Performance Monitoring (APM)

It’s essential to monitor server vitals such as CPU utilisation, memory usage and free disk space to spot the warning signs of impending doom (hands up those that have run out of disk space on a production server before 🙋‍♂️😳).

Many turn to Application Performance Monitoring (APM) software for help. But APM solutions can be expensive, require software to be installed and require system access that some people may not be comfortable with.

An Easier, Cheaper Way?

What if I told you it could be done without installing anything and set up with a simple cron job?

First you’ll need a RapidSpike Connect Anything (RCA) monitor set-up (get your 10 day free account if you don’t already have one). Once you have your unique ID, you can create the following cron jobs (be sure to replace “YOUR_ID” with your RCA unique ID):

Free Memory

*/5 * * * * FREEMEMORY=`free -m | grep Mem | awk '{print $4;}'`; curl -d "{\"id\":\"YOUR_ID\",\"ram\":$FREEMEMORY}" "https://results.rapidspike.com/rca/"

Using the free command, this extracts the free memory (in MB) and sends it to your RCA monitor every 5 minutes. Set-up an alert when this value gets low and you’ll have an early warning system for memory issues.

Available Disk Space

*/5 * * * * AVAILABLEDISK=`df | grep "/dev/sda1" | awk '{print $4;}'`; curl -d "{\"id\":\"YOUR_ID\",\"disk\":$AVAILABLEDISK}" "https://results.rapidspike.com/rca/"

Using the df command, this extracts available space on the “/dev/sda1” partition. Please set-up an alert for low disk space 🙏

CPU Usage

*/5 * * * * LOADAVG1=`cat /proc/loadavg | awk '{print $1}'`; curl -d "{\"id\":\"YOUR_ID\",\"loadavg1\":$LOADAVG1}" "https://results.rapidspike.com/rca/"

Monitoring you load average and knowing when to worry is often more useful than looking at your CPU %. “print $1” in the example is for the one minute load average, but it can be changed to “print $2” or “print $3” for five and 15 minute load average respectively.

Putting it all Together

RCA monitors allow you to send up to 5 data points (known as keys), so we can add all the commands together to make one cron that sends free memory, available disk space and CPU load average (1, 5 and 15 minutes):

*/5 * * * * FREEMEMORY=`free -m | grep Mem | awk '{print $4;}'`; AVAILABLEDISK=`df | grep "/dev/sda1" | awk '{print $4;}'`; LOADAVG1=`cat /proc/loadavg | awk '{print $1}'`; LOADAVG5=`cat /proc/loadavg | awk '{print $2}'`; LOADAVG15=`cat /proc/loadavg | awk '{print $3}'`; curl -d "{\"id\":\"YOUR_ID\",\"mem\":$FREEMEMORY,\"disk\":$AVAILABLEDISK,\"loadavg1\":$LOADAVG1,\"loadavg5\":$LOADAVG5,\"loadavg15\":$LOADAVG15}" "https://results.rapidspike.com/rca/"

All commands tested on Ubuntu 16.04 and didn’t require any additional packages to be installed. Please let us know details of any that you set-up and we’ll update this post!