Skip to content

Instantly share code, notes, and snippets.

@papertigers
Created October 31, 2019 20:33
Show Gist options
  • Save papertigers/1eea0d6850214457f3ba704b918e8b52 to your computer and use it in GitHub Desktop.
Save papertigers/1eea0d6850214457f3ba704b918e8b52 to your computer and use it in GitHub Desktop.
Triton CPU usage
#!/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