Skip to content

System Resources

Monitor system resources usage

Make sure the /var/log/sa directory exists.

Average

#!/bin/bash

for file in $(ls -la /var/log/sa/* | grep sa[0-9] | awk '{print $9}')
do
        sar -f $file | head -n 1
        printf "\n"

        printf "CPU average: "
        sar -u -f $file | grep Average: | awk -F " " '{sum = (100 - $8) } END { print sum "%" }'

        printf "Memory Average: "
        sar -r -f $file | grep Average | awk -F " " '{ sum = ($3-$5-$6)/($2+$3) * 100   } END { print sum "%" }'

       printf "\n"
done 

Peak

#!/bin/bash

for file in $(ls -la /var/log/sa/* | grep sa[0-9] | awk '{print $9}')
do
        sar -f $file | head -n 1
        printf "\n"

        printf "CPU peak: "
        sar -u -f $file | grep -v '.*CPU.*' | grep -v 'Average.*' | awk '{print $8}' | sort -nr | sed '/^$/d' | tail -1 | awk '{print 100-$1}'

        printf "Memory peak: "
        sar -u -f $file | grep -v '.*CPU.*' | grep -v 'Average.*' | sed '/^$/d' | awk '{print ($3-$5-$6)/($3+$2) * 100}' | sort -g | tail -1

       printf "\n"
done

Htop

  • Run htop
  • Press F2 (or click Setup)
  • Go to Columns
  • Add IO read anw write
  • press F10 (or click Done)