Daily server status notifications with Ntfy
A quick tip on how to send a daily notification through Ntfy with three basic server statistics: memory usage, disk usage, and CPU load.
-
If you have no intention to use the default Ntfy instance and wish to set up your own, please refer to installation instructions.
-
Create a
server-statusbash file in your chosen location and open it for editing:
nano /scripts/bash/server-status
- Paste following into the file:
#/usr/bin/bash
MEMORY_USAGE=`free -m | awk 'NR==2{printf "Memory Usage: %s/%s MB (%.0f%%)", $3,$2,$3*100/$2 }'`
DISK_USAGE=`df -h | awk '$NF=="/"{printf "Disk Usage: %.1f/%.1f GB (%s)", $3,$2,$5}'`
CPU_LOAD=`top -bn1 | grep load | awk '{printf "CPU Load: %.2f%%", $(NF-2)}'`
curl \
-H "Authorization: Basic abCdeFghiJK1" \
-H "Title: Server status report" \
-H "Tags: computer" \
-d "$MEMORY_USAGE
$DISK_USAGE
$CPU_LOAD" \
https://ntfy.example.com/vps
While replacing below values:
https://ntfy.example.com/vpswith url to the appropriate topic on your Ntfy instance,abCdeFghiJK1in curl’sAuthorizationheader with your own encoded user+password; if the instance does not require authorization, delete the whole-H "Authorization: Basic abCdeFghiJK1" \line.
-
Save the bash file with Ctrl+O.
-
Exit the bash file with Ctrl+X.
-
Make sure that the bash file is set as executable:
ls -la /scripts/bash/server-status
- Open crontab settings in edit mode:
crontab -e
- Add following line to crontab settings:
@daily /scripts/bash/server-status
If you’d like a more precise control over the time when the notification is send, please refer to crontab guru.
-
Save the crontab settings with Ctrl+O.
-
Exit the crontab settings file with Ctrl+X.