It's so rare that I search for something and actually find something useful, especially from an SEO'd-looking domain like 2daygeek.com, but I did, so I thought I'd point out this
script that emails you how much memory is being used on your server and what is using it.
Here's my version, which uses sendmail instead of mail.
#!/bin/bash
# Based on https://www.2daygeek.com/linux-shell-script-to-monitor-memory-usage/
ramusage=$(free | awk '/Mem/{printf("RAM Usage: %.2f\n"), $3/$2*100}'| awk '{print $3}' | cut -d. -f1)
SUBJECT="[memmail] Memory usage on $(hostname) at $(date)"
MESSAGE="/tmp/Mail.out"
TO="deathmtn@fastmail.com"
echo "From: bot@smallcatlabs" >> $MESSAGE
echo "Subject: $SUBJECT" >> $MESSAGE
echo "Memory Current Usage is: $ramusage%" >> $MESSAGE
echo "" >> $MESSAGE
echo "------------------------------------------------------------------" >> $MESSAGE
echo "Top Memory Consuming Processes Using top command" >> $MESSAGE
echo "------------------------------------------------------------------" >> $MESSAGE
echo "$(top -b -o +%MEM | head -n 20)" >> $MESSAGE
echo "" >> $MESSAGE
echo "------------------------------------------------------------------" >> $MESSAGE
echo "Top Memory Consuming Processes Using ps command" >> $MESSAGE
echo "------------------------------------------------------------------" >> $MESSAGE
echo "$(ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head)" >> $MESSAGE
sendmail "$TO" < $MESSAGE
rm /tmp/Mail.out