Created
October 20, 2022 20:27
-
-
Save 42wim/45be61e4950859738e8f8d2ab4118fc9 to your computer and use it in GitHub Desktop.
cpu stats docker bash
This file contains 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 | |
id=$(docker inspect $1|jq ".[]|.Id" -r) | |
mhz=$(cat /proc/cpuinfo |grep MHz|awk '{print $4}'|paste -d "+" -s|bc -l) | |
while true;do | |
allpre=$(cat /proc/stat |head -n 1|cut -d " " -f 3-9|sed s#" "#+#g|awk '{print "("$1")*1000000000/100"}'|bc) | |
acctpre=$(cat /sys/fs/cgroup/cpu,cpuacct/system.slice/docker-$id.scope/cpuacct.usage) | |
sleep 1 | |
all=$(cat /proc/stat |head -n 1|cut -d " " -f 3-9|sed s#" "#+#g|awk '{print "("$1")*1000000000/100"}'|bc) | |
acct=$(cat /sys/fs/cgroup/cpu,cpuacct/system.slice/docker-$id.scope/cpuacct.usage) | |
echo "($acct-$acctpre)/($all-$allpre)*$mhz"|bc -l | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
allpre=$(awk '/^cpu / {print ($2 + $3 + $4 + $5 + $6 + $7 + $8) * (10**7)}' </proc/stat)