Skip to content

Instantly share code, notes, and snippets.

@dmd
Created February 9, 2024 18:26
Show Gist options
  • Save dmd/4b3e8d541680fea112311e2b11a93480 to your computer and use it in GitHub Desktop.
Save dmd/4b3e8d541680fea112311e2b11a93480 to your computer and use it in GitHub Desktop.
$ cat compare-node-memory
#!/bin/bash
{
echo -e "Node\tSLURM\tActual\tpct"
for n in 1 2; do
NODE=mickey-node$n
# Get Allocated Memory from SLURM in MB and convert to GB
ALLOC_MEM_MB=$(scontrol show node $NODE | grep 'AllocMem' | awk '{print $2}' | sed 's/AllocMem=//')
ALLOC_MEM_GB=$(echo "$ALLOC_MEM_MB/1024" | bc)
# Use SSH to execute 'free -m' on the node to get actual memory usage in MB and convert to GB
ACTUAL_MEM_MB=$(ssh $NODE free -m | grep Mem: | awk '{print $3}')
ACTUAL_MEM_GB=$(echo "$ACTUAL_MEM_MB/1024" | bc)
# Calculate the percentage of actual memory usage versus SLURM allocated memory
# The percentage is rounded to the nearest integer
USAGE_PERCENT=$(echo "($ACTUAL_MEM_GB*100)/$ALLOC_MEM_GB" | bc)
echo -e "$NODE\t$ALLOC_MEM_GB\t$ACTUAL_MEM_GB\t$USAGE_PERCENT%"
done
} | column -t
ddrucker@mickey ~
$ ./compare-node-memory
Node SLURM Actual pct
mickey-node1 8 3 37%
mickey-node2 368 327 88%
ddrucker@mickey ~
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment