Skip to content

Instantly share code, notes, and snippets.

@MiPnamic
Last active February 23, 2023 01:43
Show Gist options
  • Save MiPnamic/8c43ee2201a785524c39 to your computer and use it in GitHub Desktop.
Save MiPnamic/8c43ee2201a785524c39 to your computer and use it in GitHub Desktop.
Check average Memory usage of PHP-FPM processes
#!/bin/bash
echo "Average php-fpm process memory usage:"
PHPFPM="php-fpm" # it could be just php-fpm or php-fpm-X.X (eg. php-fpm-7.1) depending on configuration
AVG=$(ps --no-headers -o "rss,cmd" -C $PHPFPM | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }')
QTY=$(ps -ylC $PHPFPM --sort:rss | tail -n +2 | wc -l)
echo "$AVG on $QTY processes"
exit 0
@nullmem
Copy link

nullmem commented May 3, 2020

Line 4 should be...
QTY=$(ps -ylC php-fpm --sort:rss | tail -n +2 | wc -l)
... because your counting the column header.

@MiPnamic
Copy link
Author

MiPnamic commented May 4, 2020

Line 4 should be...
QTY=$(ps -ylC php-fpm --sort:rss | tail -n +2 | wc -l)
... because your counting the column header.

You're totally right! I'm updating the code, thank you

@fishsaidno
Copy link

Quick 1-liner
AVG=$(ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'); QTY=$(ps -ylC php-fpm --sort:rss | tail -n +2 | wc -l); echo "$AVG on $QTY processes";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment