Yes I know there are plenty of solutions already available, but I wanted to develop my own terminal based activity monitor. This is for RPI 4, it should work on RPI 3.
curl -sSL https://raw.githubusercontent.com/PierreKieffer/pitop/master/install/install_pitop32.sh | bash
curl -sSL https://raw.githubusercontent.com/PierreKieffer/pitop/master/install/install_pitop64.sh | bash
pitop