Login show load avg, free memory, free disk

Display a login message using a message of the day (MOTD) with this script under /etc/update-motd.d/

The login message you’ll get will include:

Last Boot..........: 2020-04-12 14:29:29
Memory.............: 822 MB (Available) / 1021 MB (Total)
Load Averages......: 0.03, 0.08, 0.10 (1, 5, 15 min)
Running Processes..: 12
Free Disk Space....: 81 GB of 253 GB on /

Script

#!/usr/bin/env python3
import sys
import psutil
from datetime import datetime
import shutil
from pathlib import Path

lastboot = datetime.fromtimestamp(psutil.boot_time())
vmem = psutil.virtual_memory()
drv = Path('~').expanduser().anchor
du = shutil.disk_usage(drv)

print("Last Boot..........:", lastboot)
print(f"Memory.............: {vmem.available//1000000} MB (Available) /  {vmem.total//1000000} MB (Total)")
if sys.platform == "linux":
    print(f"Load Averages......: {psutil.getloadavg()} (1, 5, 15 min)")

print("Total Processes....:", len(psutil.pids()))
print(f"Free Disk Space....: {du.free//1000000000} GB of {du.total//1000000000} GB on {drv}")

Notes

Ubuntu 20.04 uses Python script “/usr/bin/landscape-sysinfo” to print a similar MOTD on login.