#!/usr/bin/env bash ps_output_tmp_file=/tmp/ps.out.$$ declare -i http_client_rss_usage_kb=0 declare -i http_parent_rss_usage_kb=0 declare -i http_process_max_usage_kb=0 declare -i http_server_prozesses=0 ## --- apache_version=`httpd -v | grep "version" | awk '{print$3}' | cut -d'/' -f2` apache_major_version=`echo $apache_version | awk -F \. '{ printf "%d", $1; printf "." ; printf "%d", $2 }'` ## --- #uptime=`wget -q -O - http://127.0.0.1/server-status?auto | grep -i Uptime | awk '{print$2}'` uptime=`lynx -dump http://127.0.0.1/server-status?auto | awk ' /Uptime/ {print$2}'` _now=`date +%s` _timestamp_start=`expr $_now - $uptime` starttime=`date -d \@$_timestamp_start +%c` days=`echo "scale=0 ; $uptime / 86400" | bc -l` days_rest=`echo "scale=0 ; $uptime % 86400" | bc -l` hours=`echo "scale=0 ; $days_rest / 3600" | bc -l` hours_rest=`echo "scale=0 ; $days_rest % 3600" | bc -l` minutes=`echo "scale=0 ; $hours_rest / 60" | bc -l` seconds=`echo "scale=0 ; $hours_rest % 60" | bc -l` uptime_string="$days days $hours hrs $minutes min $seconds sec" ## --- scoreborad=`wget -q -O - http://127.0.0.1/server-status?auto | grep -i Scoreboard | awk '{print$2}'` _scoreborad_in_use=`echo -n "$scoreborad" | sed -e 's/[\.]//g'` _scoreboard_busy=`echo -n "$_scoreborad_in_use" | sed -e 's/[_]//g'` _scoreboard_idle=`echo -n "$_scoreborad_in_use" | sed -e 's/[^_]//g'` workers_in_use=`echo -n "$_scoreborad_in_use" | wc -m` idle_workers=`echo -n "$_scoreboard_idle" | wc -m` busy_workers=`echo -n "$_scoreboard_busy" | wc -m` #max_simultanous_connections=`echo -n "$scoreborad" | wc -m` ## --- mpm=`lynx -dump http://127.0.0.1/server-info?server | awk ' /MPM Name:/ {print tolower($3)}'` server_root=`lynx -dump http://127.0.0.1/server-info?server | awk ' /Server Root:/ {print$3}'` config_file=`lynx -dump http://127.0.0.1/server-info?server | awk ' /Config File:/ {print$3}'` config_file_found=false _default_2_2_prefork_server_limit=256 _default_2_2_prefork_max_clients=150 _default_2_2_prefork_max_requests_per_child=0 _default_2_2_worker_server_limit=16 _default_2_2_worker_max_clients=150 _default_2_2_worker_threads_per_child=25 _default_2_2_worker_max_requests_per_child=0 _default_2_4_prefork_server_limit=250 _default_2_4_prefork_max_request_workers=25 _default_2_4_prefork_max_connections_per_child=0 _default_2_4_event_server_limit=16 _default_2_4_event_threads_per_child=25 _default_2_4_event_max_request_workers=400 _default_2_4_event_max_connections_per_child=0 if grep -i -E "^\s*Include\s+conf/extra/httpd-mpm.conf" $config_file > /dev/null 2>&1 ; then config_file_found=true found=false while read line ; do if echo $line | grep -i "IfModule mpm_${mpm}_module" > /dev/null 2>&1 ; then found=true continue fi if $found ; then if echo $line | grep -i "ServerLimit" > /dev/null 2>&1 ; then server_limit=`echo $line | grep -i "ServerLimit" | awk '{print$2}'` fi if echo $line | grep -i "MaxClients" > /dev/null 2>&1 ; then max_clients=`echo $line | grep -i "MaxClients" | awk '{print$2}'` fi if echo $line | grep -i "ThreadsPerChild" > /dev/null 2>&1 ; then threads_per_child=`echo $line | grep -i "ThreadsPerChild" | awk '{print$2}'` fi if echo $line | grep -i "MaxRequestWorkers" > /dev/null 2>&1 ; then max_request_workers=`echo $line | grep -i "MaxRequestWorkers" | awk '{print$2}'` fi if echo $line | grep -i "MaxConnectionsPerChild" > /dev/null 2>&1 ; then max_connections_per_child=`echo $line | grep -i "MaxConnectionsPerChild" | awk '{print$2}'` fi if echo $line | grep -i "MaxRequestsPerChild" > /dev/null 2>&1 ; then max_requests_per_child=`echo $line | grep -i "MaxRequestsPerChild" | awk '{print$2}'` fi if echo $line | grep -i " /dev/null 2>&1 ; then break; fi fi done < ${server_root}/conf/extra/httpd-mpm.conf fi if [ "$apache_major_version" = "2.4" ]; then if [ "$mpm" = "event" ];then if [ -z "$server_limit" ]; then server_limit=$_default_2_4_event_server_limit fi if [ -z "$threads_per_child" ]; then threads_per_child=$_default_2_4_event_threads_per_child fi if [ -z "$max_request_workers" ]; then max_request_workers=$_default_2_4_event_max_request_workers fi if [ -z "$max_connections_per_child" ]; then max_connections_per_child=$_default_2_4_event_max_connections_per_child fi max_processes=$server_limit max_simultanous_connections=`expr $server_limit \* $threads_per_child` elif [ "$mpm" = "prefork" ];then if [ -z "$server_limit" ]; then server_limit=$_default_2_4_prefork_server_limit fi if [ -z "$max_request_workers" ]; then max_request_workers=$_default_2_4_prefork_max_request_workers fi if [ -z "$max_connections_per_child" ]; then max_connections_per_child=$_default_2_4_prefork_max_connections_per_child fi max_processes=$max_request_workers max_simultanous_connections=$max_request_workers max_simultanous_connections_msg="Based on \"Max Request Workers\" NOT \"Server Limit" fi elif [ "$apache_major_version" = "2.2" ]; then if [ "$mpm" = "worker" ];then if [ -z "$server_limit" ]; then server_limit=$_default_2_2_worker_server_limit fi if [ -z "$threads_per_child" ]; then threads_per_child=$_default_2_2_worker_threads_per_child fi if [ -z "$max_clients" ]; then max_clients=$_default_2_2_worker_max_clients fi if [ -z "$max_requests_per_child" ]; then max_requests_per_child=$_default_2_2_worker_max_requests_per_child fi max_processes=$max_clients max_simultanous_connections=$max_clients max_simultanous_connections_msg="Based on \"Max Clients\" NOT \"Server Limit" elif [ "$mpm" = "prefork" ];then if [ -z "$server_limit" ]; then server_limit=$_default_2_2_prefork_server_limit fi if [ -z "$max_clients" ]; then max_clients=$_default_2_2_prefork_max_clients fi if [ -z "$max_requests_per_child" ]; then max_requests_per_child=$_default_2_2_prefork_max_requests_per_child fi max_processes=$max_clients max_simultanous_connections=$max_clients max_simultanous_connections_msg="Based on \"Max Clients\" NOT \"Server Limit" fi fi ## --- ps --no-headers -ylC httpd | awk '{print$2" "$8}' > $ps_output_tmp_file while read _UID _RSS ; do if [ "$_UID" = "0" ]; then http_parent_rss_usage_kb=$_RSS else http_client_rss_usage_kb=`expr $http_client_rss_usage_kb + $_RSS` let http_server_prozesses++ if [ $_RSS -gt $http_process_max_usage_kb ]; then http_process_max_usage_kb=$http_client_rss_usage_kb fi fi done < $ps_output_tmp_file cur_memory_usage_kb=`echo "scale=0; $http_parent_rss_usage_kb + $http_client_rss_usage_kb" | bc -l` cur_memory_usage_mb=`echo "scale=3; $cur_memory_usage_kb/1024" | bc -l` each_process_usage_kb=`echo "scale=3; $http_client_rss_usage_kb/$http_server_prozesses" | bc -l` each_process_usage_mb=`echo "scale=3; $each_process_usage_kb/1024" | bc -l` http_process_max_usage_mb=`echo "scale=3; $http_process_max_usage_kb/1024" | bc -l` declare -i _tmp_val=0 max_memory_limit_avarage_mb=0 max_memory_limit_avarage_mb=`echo "scale=3; $each_process_usage_mb * $max_processes" | bc -l` max_memory_limit_avarage_gb_str="" _tmp_val=`echo "scale=0; $max_memory_limit_avarage_mb / 1" | bc -l` if [ $_tmp_val -gt 1023 ]; then max_memory_limit_avarage_gb=`echo "scale=3; $max_memory_limit_avarage_mb/1024" | bc -l` max_memory_limit_avarage_gb_str=" ($max_memory_limit_avarage_gb GB)" fi max_memory_limit_max_mb=0 max_memory_limit_max_mb=`echo "scale=3; $http_process_max_usage_mb * $max_processes" | bc -l` max_memory_limit_max_gb_str="" _tmp_val=`echo "scale=0; $max_memory_limit_max_mb / 1" | bc -l` if [ $_tmp_val -gt 1023 ]; then max_memory_limit_max_gb=`echo "scale=3; $max_memory_limit_max_mb/1024" | bc -l` max_memory_limit_max_gb_str=" ($max_memory_limit_max_gb GB)" fi ## --- echo "" echo "----- Current Status" echo "" echo -e "\tApache Server Version.............: $apache_version" #echo -e "\tApache Major Version..............: $apache_major_version" echo "" echo -e "\tStart Time........................: $starttime" echo -e "\tUptime............................: $uptime_string" echo echo -e "\tMulti-Processing Module (MPM).....: $mpm " if [ -n "$server_root" ];then echo "" echo -e "\tServer Rooot Directory............: $server_root" fi if [ -n "config_file" ]; then echo -e "\tConfig File.......................: $config_file" fi echo "" echo -e "\tNumber Apache (Client) Prozesses..: $http_server_prozesses" echo "" echo -e "\tCurrent Memory Usage..............: $cur_memory_usage_mb MB" echo -e "\tEach Process Usage (Avarage)......: $each_process_usage_mb MB" echo "" echo -e "\tWorkers in Use....................: $workers_in_use" echo -e "\tBusy Workers......................: $busy_workers" echo -e "\tIdle Workers......................: $idle_workers" echo "" echo "" if $config_file_found ; then echo "----- MPM Configuration (read from included config file httpd-mpm.conf)" else echo "----- MPM Configuration (config file httpd-mpm.conf NOT included - assuming defaults)" fi echo "" echo -e "\tMulti-Processing Module (MPM).....: $mpm " echo "" echo "" echo -e "\tServer Limit (Processes)..........: $server_limit" if [ -n "$max_clients" ]; then echo -e "\tMax Clients.......................: $max_clients" fi if [ -n "$threads_per_child" ]; then echo -e "\tThreads Per Child.................: $threads_per_child" fi if [ -n "$max_request_workers" ]; then echo -e "\tMax Request Workers...............: $max_request_workers" fi if [ -n "$max_connections_per_child" ]; then echo -e "\tMax Connections Per Child.........: $max_connections_per_child" elif [ -n "$max_requests_per_child" ]; then echo -e "\tMax Requests Per Child............: $max_requests_per_child" fi echo "" echo -e "\tMax Simultanous Connectons........: $max_simultanous_connections" if [ -n "$max_simultanous_connections_msg" ];then echo -e "\t $max_simultanous_connections_msg" fi echo "" echo "" echo "----- Memory Limit (estimated values!!)" echo "" echo -e "\tMax Memory (based on avarage usage)..: $max_memory_limit_avarage_mb MB$max_memory_limit_avarage_gb_str" echo "" echo -e "\tMax Memory (bades on max usage)......: $max_memory_limit_max_mb MB$max_memory_limit_max_gb_str" echo "" echo "" rm -f $ps_output_tmp_file exit 0