
When interval is 0.0 or None compares system CPU times elapsed since last call or module import, returning immediately. When interval is > 0.0 compares system CPU times elapsed before and after the interval (blocking). Return a float representing the current system-wide CPU utilization as a percentage. Psutil.cpu_percent(interval=None, percpu=False) Individual CPUs: 11.00% 8.50% 11.90% 8.50% 9.90% 7.60% 11.50% 12.30%įor more information on how the psutil.cpu_percent(interval=2) python call works, see the official psutil.cpu_percent(interval=None, percpu=False) documentation here: Sample output: notice that I have 8 cores, so there are 8 numbers after "Individual CPUs:": Total: 10.15% printf "%b" "import psutil\nprint(''.format(' '.join(cpu_percent_cores_str)))\n\ This calls python3 and uses the cross-platform psutil module. You will receive a output like the one below by mail.Do this to see the overall CPU usage. Note: You will be getting an email alert everyday at 8 o’clock. # crontab -eĠ 8 * * * /bin/bash /opt/scripts/cpu-memory-swap-2.sh # chmod +x /opt/scripts/cpu-memory-swap-2.shįinally add a cronjob to automate this. Set an executable Linux file permission to “cpu-memory-swap-2.sh” file. Scpu=$(ssh $server cat /proc/stat | awk '/cpu/')Įcho "$server, $scpu, $smem, $sswap" > /tmp/cpu-mem-swap.csvĮcho "CPU and Memory Report for `date +"%B %Y"`" | mailx -s "CPU and Memory Report on `date`" -a /tmp/cpu-mem-swap.csv /tmp/cpu-mem-swap.csv # vi /opt/scripts/cpu-memory-swap.shĮcho "-"Įcho "Server_Name CPU(%) Memory(%) Swap(%)"įor server in `more /opt/scripts/server-list.txt`

This script allows you to check CPU, memory and swap usage on multiple Linux system from the terminal. Method-1 : Shell Script to Check CPU, Memory and Swap usage on Multiple Linux System Three shell scripts are added in this tutorial to generate a report.Įach bash script has written with unique features and choose the one you need.Īlso, you can modify this script based on your needs. You can use this script to generate a CPU, memory and swap usage for a multiple Linux system. This script will help you to create a report for you.
