vm_stat is the plain old way to see what the memory manager is doing. The first thing to know is that it counts pages, not megabytes.
Run it without arguments and the man page says you get all accumulated statistics along with the page size:
vm_stat
To turn a page count into megabytes, multiply by the page size. This reads the size from sysctl and prints the free pages in MB:
vm_stat | awk -v s=$(sysctl -n hw.pagesize) '/Pages free/ {gsub(/\./,"",$3); printf "%.0f MB free\n", $3*s/1048576}'
With an interval it keeps printing, and -c stops it after a number of rounds:
vm_stat -c 5 2
That prints five reports, two seconds apart. The first line after each banner shows the system-wide totals, and every line after it shows the change since the previous one. An interval of 1 therefore gives you values per second.
A few of the lines the man page explains:
Pages wired downcounts pages that cannot be paged outPages stored in compressorcounts pages whose contents sit in the in-memory compressor poolSwapinsandSwapoutscount compressed data moved to and from swap files, in units of pages
The caveat is the Pages free line. The man page says file-backed pages can be evicted and read back under pressure, so free pages alone say little about whether the Mac is short on memory. The page I read also says meminfo(1) is the modern, preferred tool for physical memory and should be used instead of vm_stat where possible, so check whether your macOS has it.
Further reading: vm_stat man page