Joe Huss

Generation

code to explanationFri, 20 Jan 2023

if [ -e /proc/vz/fairsched/cpu.proc.stat ]; then grep -H "^cpu" /proc/vz/fairsched/*/cpu.proc.stat | tr / " " | tr : " " | awk '{ print $4 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 " " $12 " " $13 " " $14 }'; else grep "^cpu" /proc/stat | awk '{ print 0 " " $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 }'; fi

The code check if there is any container running in the host. If there is a container running, the code will take the information from the container (inside /proc/vz/fairsched/cpu.proc.stat) to print the cpu usage. Otherwise, the code will get the cpu usage directly from the host (inside /proc/stat).

Questions about programming?Chat with your personal AI assistant