I have tried the following command to check the an average memory usage by single PHP-FPM process
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
and I got an error awk: cmd. line:1: fatal: division by zero attempted
And this command
total=0; for i in `ps -C php-fpm -o rss=`; do total=$(($total+$i)); done; echo "Memory usage: $total kb";
Memory usage: 0 kb
ps -ef | grep php
root 9435 1 0 11:42 ? 00:00:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
somename+ 9438 9435 0 11:42 ? 00:00:00 php-fpm: pool somename-1
somename+ 9439 9435 0 11:42 ? 00:00:01 php-fpm: pool somename-1
...
...
For the
ps
option-C
to match, you need to make sure you're looking for the right string - not the extended command name shown by default with e.g.-ef
, but what thec
option shows in combination with e.g.ax
.Compare:
In this example, the string matchable with
-C
isphp-fpm7.0
:I don't know where I found it, but it works!