Skip to content

Instantly share code, notes, and snippets.

@ayumi
Created December 12, 2017 22:29
Show Gist options
  • Save ayumi/51cc68aea95c16195ff729ba5b085caa to your computer and use it in GitHub Desktop.
Save ayumi/51cc68aea95c16195ff729ba5b085caa to your computer and use it in GitHub Desktop.
Shell script to calculate Xen aggregate VM CPU usage.
#!/bin/sh
# Calculate aggregate VM CPU usage as integer percentage (eg 42).
# Denominator for awk division is 4 for 4 vCPUs -- change if needed.
xentop -b -d 1 -i 2 | tac | sed '/MAXMEM/,$d' | tr -s ' ' | sed -e 's/^[ \t]*//' | cut -d ' ' -f 4 | awk '{s+=$1} END {printf "%.0f", int(s/4)}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment