How to find ip's causing high cpu on your cloudways server?

I was strugling with how to find ip’s causing high cpu on my cloudways server.
via cloudways support they suggested me to run this script in ssh terminal:

run

$ cd /home/master/applications

And in ‘application’ directory run this script:

for A in $(ls -la | awk '{print $NF}'); do echo $A && awk '{print $1,$7}' $A/logs/apache_*.access.log | cut -d? -f1 | sort | uniq -c |sort -nr | head -n 5 | awk -F";" '{print $1}' ; done

this will give you a list of most used ip’s per application

this was very useful for me, so i wanted to share it here with you

1 Like

you can then block the ip’s in .htaccess: