Skip to content

Instantly share code, notes, and snippets.

@abdallah
Created February 28, 2018 11:39
Show Gist options
  • Save abdallah/4ed9bd20315705c86ba21b6cc3fb68f0 to your computer and use it in GitHub Desktop.
Save abdallah/4ed9bd20315705c86ba21b6cc3fb68f0 to your computer and use it in GitHub Desktop.
Log PID and path of process causing high CPU usage (php-fpm)
#!/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