Created
March 7, 2016 08:13
-
-
Save fanyeren/d290ebbc62d234e393c6 to your computer and use it in GitHub Desktop.
linux 空闲率计算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cc=$(grep -c processor /proc/cpuinfo) | |
uptime=$(cat /proc/uptime | awk '{print $1}') | |
idletime=$(cat /proc/uptime | awk '{print $2}') | |
idle_ratio=$(echo $cc $uptime $idletime | perl -ne '{my @input = split(/\s+/, $_); my $idle = $input[2] / ($input[0] * $input[1]); print $idle, "\n";}') | |
idle_ratio=$(printf "%.04s" $idle_ratio) | |
echo -e "\t\t\t\t\t\e[1;31m开机以来空闲率:$idle_ratio\e[0m\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment