Created
February 28, 2018 11:39
-
-
Save abdallah/4ed9bd20315705c86ba21b6cc3fb68f0 to your computer and use it in GitHub Desktop.
Log PID and path of process causing high CPU usage (php-fpm)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# very specific need | |
top_process=$(ps -eo pid,cmd,%cpu --sort=-%cpu | head -n2 | tail -n1) | |
if [[ $top_process == *sometest* ]]; then | |
PATHTOPROCESS=$(echo $top_process| awk '{print $1}' | xargs lsof -p | grep public_html) | |
logger -it HIGHCPU "Process $top_process in $PATHTOPROCESS" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment