Difference between revisions of "Cpu-usage.sh"

From DarkWiki
Jump to: navigation, search
(Created page with "Category:Scripts Category:How to Category:Bash Category:Ubuntu Category:System performance This script demonstrates how to calculate the current CPU usage ...")
 
(No difference)

Latest revision as of 06:48, 12 April 2016

This script demonstrates how to calculate the current CPU usage (as a percentile) on a Ubuntu box. It takes into account the number of processors available.

Script

#!/bin/bash

CPUCOUNT=$(cat /proc/cpuinfo | grep processor | wc -l)
LOADAVG=$(cat /proc/loadavg | awk '{print $1}')

NRML=$(echo "$LOADAVG * 100 / $CPUCOUNT" | bc -l | sed "s/\(.*\...\).*$/\1/g")

echo $NRML