Skip to content

Instantly share code, notes, and snippets.

@mrevjd
Created June 2, 2024 22:52
Show Gist options
  • Select an option

  • Save mrevjd/4ce4ef1c98cb52376f5c5dc68854d90a to your computer and use it in GitHub Desktop.

Select an option

Save mrevjd/4ce4ef1c98cb52376f5c5dc68854d90a to your computer and use it in GitHub Desktop.

Revisions

  1. mrevjd created this gist Jun 2, 2024.
    10 changes: 10 additions & 0 deletions calc_php-fpm.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/usr/bin/env bash

    RESERVED_MEM_GB=${1:-0}

    PHP_FPM_MEM=$(ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm|grep pool| awk '{sum+=$1; count++} END {print sum/count}')
    TOTAL_MEM_GB=$(free -m | awk '/^Mem:/{print $2}')

    MEM_RATIO=$(echo "scale=2; ($TOTAL_MEM_GB - $RESERVED_MEM_GB) / $PHP_FPM_MEM" | bc)

    echo "Total Workers: $MEM_RATIO"