I am not sure if it is even possible, but can I somehow restart service when memory has been already used over 90%?
I mean script will check memory, and if memory has been used over 90% it will restart/execute restart of my service?
Have a look at SystemD's resource-control.
Combining MemoryMax
and Restart=always
should do the trick.
Wrote own script in the end
m=`free -m | head -n value | tail -n 1 | tr -s " " | cut -d " " -f value`
if [ $m -ge 10000 ]; then
systemctl restart service
fi