GoAdmio

memoryavg

Record the server's current memory use, print the average of all recorded samples, and alert the administrator by email and WhatsApp when that average is above 70%

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/memoryavg watches how much of the server's memory is in use over time, so a short spike doesn't cause an alert but steady heavy use does. Each time it runs, it:

For a single moment in time and the processes behind it, use mem instead.

[!NOTE] The command is meant to give a weekly average, but the file it reads is not cleared by this script. See The weekly reset. Until the file is cleared, the average covers all samples ever recorded in it.


Quick start

/go/memoryavg

Syntax

/go/memoryavg
Form Behavior
/go/memoryavg Adds a sample, prints the average, and sends the alert if the average is above 70%.

Options

This command has no options. Arguments are only written to the log file.


Output

The command prints one whole number: the average memory use in percent, without a % sign. The decimals are cut off, not rounded.

42

Each run adds a sample, so the first run after the file is cleared shows the current memory use itself.

The alert

When the average is above 70 (71 or more), the administrator gets an email and a WhatsApp message. Both say:

High Memory Usage Averages (73 %)

[!NOTE] The command sends both messages every time it runs while the average stays above 70. Nothing limits how often alerts repeat.

Files

File Use
/var/log/memory.log One sample per line, in percent.
/var/log/go/memoryavg.log A record of each time the command ran.

Examples

# Add a sample and show the average
/go/memoryavg
# Reset the average by deleting the samples
sudo rm -f /var/log/memory.log
# See the recorded samples
tail -n 20 /var/log/memory.log

Troubleshooting

Symptom Likely cause Fix
The average never drops, even after memory use is low memory.log is not cleared, so old samples keep counting. Delete /var/log/memory.log to start over. See The weekly reset.
The load average history disappears at the start of each week On Sunday in the 00 hour, this command deletes /var/log/load.log, which belongs to loadavg. See The weekly reset.
Alerts repeat on every run An alert is sent on every run while the average is above 70. Fix the memory problem, or lower how often the command runs.
No alerts arrive although the average is high The average is 70 or lower, the administrator's details are missing, or sending is not working. Check the address with email, and test mail with checkmail.
One busy moment doesn't change the average The average is the plain mean of all samples, so a spike is diluted. Use mem to see current use.
The command starts slowly or seems to hang It first looks up the server's public IP from the internet, with no time limit. Check the server's internet access.
The number looks different from other tools The sample uses the "used" column of free, which does not count memory the system can reclaim. Compare with free or mem.

Details

How the average works

  1. Writes the command and its arguments to /var/log/go/memoryavg.log.
  2. Measures current memory use as used memory divided by total memory, as reported by free, rounded down to a whole percent.
  3. Appends that number as a new line in /var/log/memory.log.
  4. Averages all the lines in the file and rounds down.
  5. Prints the average, and sends the alert if it is above 70.

The average is a plain mean of the samples, with no weighting by time. It is only as accurate as the number of samples: it reflects how often the command runs.

The weekly reset

At the start of the script, if the current time is Sunday in the 00 hour, the command deletes /var/log/load.log. That is the sample file of loadavg, not this command's /var/log/memory.log. So:

To reset the memory average, delete /var/log/memory.log yourself.

Other values it reads

The script also reads the server hostname, the public IP address, and the administrator's email, mobile number, and WhatsApp settings from GoAdmio's settings database, and computes the memory in a readable format, but it does not use them. The public IP lookup is the only part that needs internet access.

Sending the alert

The email and the WhatsApp message are sent through GoAdmio's own sending helpers, to the administrator's contact details saved in GoAdmio. To change the email address, use email.


See also

Command Description
mem Check the top ten memory-consuming commands or services
loadavg Check the weekly server load average
cpu Show the server's CPU load and its top CPU-consuming processes, and send an alert when one process uses most of the CPU
heal Monitor key services, memory, load, and disk, and automatically fix problems (Auto-Heal)
swap Create a swap file sized to RAM and set vm.swappiness
slice Apply server-wide CPU and memory limits to user-.slice
email Change the administrator email address GoAdmio uses for server notifications