Skip to content

Example wesplot pipelines

Shuhao Wu edited this page Jun 12, 2023 · 15 revisions

All-core CPU usage via sar

You need to first install sar, which is available via apt install sysstat on Debian/Ubuntu. Then:

S_TIME_FORMAT=ISO sar 1 | \
  awk '{ if ($NF ~ /^[0-9]+[.]?[0-9]*$/) print 100-$NF; fflush(); }' | \
  wesplot -t "CPU Utilization" -c "CPU%" -m 0 -M 100

Memory and swap plots via free

Confirm that the output of free -m is the following where the memory usage in MB is on the 3rd column of the 2nd line and swap usage in MB is the 3rd column of the 3rd line.

               total        used        free      shared  buff/cache   available
Mem:           31815       13002         972        3023       17840       15334
Swap:          10239         610        9629

Then:

max_memory=32000
{
  while true; do
    free -m \
      | awk 'NR==2{ line=line " " $3 } NR==3{ line=line " " $3; print(line); fflush(); }'
    sleep 2
  done;
} | wesplot -t "Memory usage" -u "MB" -c "Memory" -c "Swap" -m 0 -M $max_memory

CPU Package temperature with sensors

{ 
  while true; do 
    sensors | grep -oP 'Package.*?\+\K[0-9.]+'
    sleep 1
  done 
} | wesplot -t "CPU package temp" -u "°C" -m 20 -M 120

All core frequency plots

This also shows off awk merging multiple lines into a single line. Need to modify this (the number 16 and the -c flags) for the number of CPUs you have.

{ 
  while true; do 
    cat /proc/cpuinfo \
      | grep "MHz" \
      | awk -F: '{ print $2 }' \
      | awk '{line=line " " $0} NR%16==0{print substr(line,2); line=""; fflush(); }'
    sleep 1
  done 
} | wesplot -t "CPU Freq" -c CPU0 -c CPU1 -c CPU2 -c CPU3 -c CPU4 -c CPU5 -c CPU6 -c CPU7 -c CPU8 -c CPU9 -c CPU10 -c CPU11 -c CPU12 -c CPU13 -c CPU14 -c CPU15 -u MHz
Clone this wiki locally