Created
October 31, 2019 20:33
-
-
Save papertigers/1eea0d6850214457f3ba704b918e8b52 to your computer and use it in GitHub Desktop.
Triton CPU usage
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 | |
# | |
# Print CPU Subscription % for all Servers | |
# | |
# Sorting | |
# Default - hostname | |
# -p - Subscription % | |
SORT="+1" | |
while getopts p OPTIONS | |
do | |
case $OPTIONS in | |
p) SORT="-n +4" ;; | |
*) echo "Usage: cpu.sh [-p]"; exit ;; | |
esac | |
done | |
sdc-cnapi /servers?extras=all | json -aH sysinfo vms | egrep "Hostname|Total Cores|cpu_cap|^ \"UUID" | sed -e 's/[":,]//g' -e 's/^[ ]*//' | | |
awk ' | |
BEGIN {F="1";P="0"} | |
{ if ($1 == "UUID") { if( F == "0") { print UUID, HOST, CAPS, CORES*100, (CAPS*100)/(CORES*100) ; P=0 } | |
F="0"; CAPS=0; UUID=$2 }} | |
{ if ($1 == "Hostname") { HOST=$2 ; P=1}} | |
{ if ($1 == "cpu_cap") { CAPS+=$2 }} | |
{ if ($1 == "CPU") { CORES=$4 }} | |
END { if (P == 1) { print UUID, HOST, CAPS, CORES*100, (CAPS*100)/(CORES*100) }}' > /var/tmp/cpu.$$ | |
( echo "UUID" "HOSTNAME" "VM_TOTAL_CAPS" "SERVER_TOTAL" "SUBSCRIPTION(%)" ; cat /var/tmp/cpu.$$ | eval sort $SORT ) | column -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment