#!/bin/bash
# get the min and max online numa node
read -r minNode maxNode < <(tr '-' ' ' </sys/devices/system/node/online)
# for each numa node
for ((node = minNode; node <= maxNode; node++)); do
# capture info on that node
nodeData=$(cat "/sys/devices/system/node/node${node}/meminfo")
total=$(awk '$3 == "MemTotal:" {print $4}' <<<"${nodeData}")
free=$(awk '$3 == "MemFree:" {print $4}' <<<"${nodeData}")
used=$(awk '$3 == "MemUsed:" {print $4}' <<<"${nodeData}")
# calculate percentage of used memory
percent=$(awk '{print 100 * $1 / $2}' <<<"${used} ${total}")
# print the formatted row for this node
# shellcheck disable=SC2046,SC2183
printf 'numactl,node=%s size=%s,free=%s,used=%s,used_percent=%s\n' \
"${node}" "${total}" "${free}" "${used}" "${percent}"
done
|