How to get an alert when I'm about to run out of Ram?

My own experience is that when you run out of RAM and switch to swap, there is some slight slow down.
This may vary depending on how the user sets ups swappiness.
It does not freeze or crash.
You can also periodically clear out RAM:

This method is quick and effective.