check an average memory usage by single PHP-FPM process

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 the c option shows in combination with e.g. ax.

Compare:

% ps -ef | grep '[f]'pm
www-data  3014  3714  2 19:09 ?        00:01:16 php-fpm: pool www
root      3714     1  0 Srp03 ?        00:00:32 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 10644  3714  2 18:14 ?        00:02:35 php-fpm: pool www
www-data 18448  3714  2 19:42 ?        00:00:28 php-fpm: pool www

% ps axc | grep '[f]'pm
 3014 ?        S      1:17 php-fpm7.0
 3714 ?        Ss     0:32 php-fpm7.0
10644 ?        S      2:35 php-fpm7.0
18448 ?        S      0:28 php-fpm7.0

In this example, the string matchable with -C is php-fpm7.0:

% ps -C php-fpm7.0 -o rss=
32516
65952
61468
61012