Definitely use fail2ban as Simon's answer recommends, because it protects against other issues in its default configuration. You mention the machine is running out of memory though, and fail2ban needs to monitor your logs and react to these bots, which uses memory. You may still run out of resources and if that happens you need something more efficient.
I recommend you also use
iptables directly. Fail2ban uses iptables to react to attacks by dropping problematic IP addresses, but there is no reason you cannot be proactive and simply 'preload' a block of known bad IPs.
As an example, here is what I use to silently drop poneytelecom's entire range of IPs:
sudo iptables -A INPUT -s 220.127.116.11/16 -j DROP
To efficiently drop all traffic from the top 8 'greatest hits' in your screenshot you could use
sudo iptables -A INPUT -s 18.104.22.168/16 -j DROP
Two important things to remember about this though. Changes will not persist across reboots and you may block legitimate visitors coming from these IP address ranges. For the latter, you need to look up the IP addresses (try WHOIS) and make a decision whether they are an acceptable loss. For me, poneytelecom definitely was.
And to make your iptables rule(s) persistent on any Debian-based distro try the
iptables-persistent package. Install and enable it with this command:
sudo aptitude install iptables-persistent && sudo service iptables-persistent start
If you change any rules later you will need to save them with
sudo service iptables-persistent save. (also note
iptables-persistent may be named
netfilter-persistent in some distros)
Good luck and careful with
iptables, my examples will work perfectly and are tested but if you are adapting and testing new ones make sure you read the man pages and understand the consequences of each new rule, or you risk making the server inaccessible to all, and you may have to re-image and start over.