richardforth / apache2buddy

apache2buddy
Apache License 2.0
386 stars 72 forks source link

Error: Illegal division by zero at line 987 #411

Closed JoniJnm closed 1 year ago

JoniJnm commented 1 year ago

Output:

Use of uninitialized value $proc_mem_usages[0] in division (/) at /tmp/tool.pl
    line 973 (#2)
Use of uninitialized value $count in division (/) at /tmp/tool.pl line 987 (#2)

Illegal division by zero at /tmp/tool.pl line 987 (#3)
    (F) You tried to divide a number by 0.  Either something was wrong in
    your logic, or you need to put a conditional in to guard against
    meaningless input.

Uncaught exception from user code:
    Illegal division by zero at /tmp/tool.pl line 987.
    main::get_memory_usage("/usr/sbin/apache2", "app", "average") called at /tmp/tool.pl line 2806
richardforth commented 1 year ago

Hi,

There isn't enough information here to investigate further, can you please tell me:

What operating system you were running this on, and what version of apache you had installed?

Thanks Richard

richardforth commented 1 year ago

Can you also share with me the exact command you ran to get this error?

JoniJnm commented 1 year ago

Yes, it's apache 2.4 on ubuntu 22.04 docker image:

docker run --rm -it ubuntu:22.04 bash

inside:

apt update
apt install -y curl apache2 python3-distro net-tools
curl -sL -o /tmp/apache2buddy.pl https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl
apachectl -D BACKGROUND
perl /tmp/apache2buddy.pl
output: ``` ################################################# apache2buddy.pl report for af2050ce9388 (x.x.x.x) ################################################# [ OK ] This script is being run as root. [ OK ] The utility 'pmap' exists and is available for use: /usr/bin/pmap [ OK ] The utility 'netstat' exists and is available for use: /usr/bin/netstat [ @@ ] Unable to locate the PHP binary. PHP specific checks will be skipped. [ OK ] The utility 'apachectl' exists and is available for use: /usr/sbin/apachectl [ OK ] The port (port 80) is a valid port. [ -- ] We are attempting to discover the operating system type and version number ... [ !! ] Unable to locate the 'python' binary. [ OK ] The 'python3' binary exists and is available for use: /usr/bin/python3 :3: DeprecationWarning: distro.linux_distribution() is deprecated. It should only be used as a compatibility shim with Python's platform.linux_distribution(). Please use distro.id(), distro.version() and distro.name() instead. [ -- ] Distro: Ubuntu [ -- ] Version: 22.04 [ -- ] Codename: Jammy Jellyfish [ OK ] This distro is supported by apache2buddy.pl. [ OK ] This distro version is supported by apache2buddy.pl. [ -- ] Hostname: af2050ce9388 [ -- ] Primary IP: x.x.x.x [ -- ] We are checking the service running on port 80... [ -- ] The process listening on port 80 is /usr/sbin/apache2 [ -- ] The process running on port 80 is Apache/2.4.52 (Ubuntu). [ -- ] The full path to the Apache config file is: /etc/apache2/apache2.conf [ -- ] Apache is using event model. [ OK ] Running user (www-data) matches config (www-data). [ -- ] pidfile setting is /var/run/apache2$SUFFIX/apache2.pid. [ -- ] Actual pidfile is /var/run/apache2/apache2.pid. [ -- ] Parent PID: 3609. [ OK ] Memory usage of parent PID is less than 50MB: 1384 Kilobytes. [ -- ] Apache has been running 0d 0h 00m 33s. [ !! ] *** LOW UPTIME ***. [ @@ ] The following recommendations may be misleading - apache has been restarted within the last 24 hours. [ -- ] Your server has 32001 MB of PHYSICAL memory. [ >> ] ServerLimit directive not found, assuming default values. [ -- ] Your ServerLimit setting is 16. [ -- ] Your ThreadsPerChild setting is 25. [ -- ] Your ThreadsPerChild setting for worker/event MPM is 25 [ -- ] Your ServerLimit setting for worker/event MPM is 16 [ -- ] Your MaxRequestWorkers setting is 150. [ OK ] Current Apache Process Count is 3, including the parent PID. [ -- ] Number of vhosts detected: 0. [ OK ] Current Apache vHost Count is less than maxrequestworkers. [ @@ ] vHost Count works only when we have NameVirtualHosting enabled, check config manually, they may only have the default vhost. [ -- ] This server is NOT running Plesk. [ -- ] This server is NOT running cPanel. [ -- ] This server is NOT running Virtualmin. [ OK ] No additional services were detected. [ OK ] No large log files were found in /var/log/apache2. [ OK ] MaxClients has not been hit recently. [ >> ] Apache only logs maxclients/maxrequestworkers hits once in a lifetime, if no restart has happened this event may have been rotated away. [ >> ] As a backup check, please compare number of running apache processes (minus 1 for parent) against maxclients/maxrequestworkers. [ >> ] For more information see https://github.com/apache/httpd/blob/0b61edca6cdda2737aa1d84a4526c5f9d2e23a8c/server/mpm/prefork/prefork.c#L809 [ OK ] No package updates found. [ -- ] apache2 is currently using 12.82 MB of memory. Use of uninitialized value $proc_mem_usages[0] in division (/) at /tmp/apache2buddy.pl line 967 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl will try to tell you the name of the variable (if any) that was undefined. In some cases it cannot do this, so it also tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program. Use of uninitialized value $proc_mem_usages[0] in division (/) at /tmp/apache2buddy.pl line 973 (#1) Use of uninitialized value $count in division (/) at /tmp/apache2buddy.pl line 987 (#1) Illegal division by zero at /tmp/apache2buddy.pl line 987 (#2) (F) You tried to divide a number by 0. Either something was wrong in your logic, or you need to put a conditional in to guard against meaningless input. Uncaught exception from user code: Illegal division by zero at /tmp/apache2buddy.pl line 987. main::get_memory_usage("/usr/sbin/apache2", "www-data", "average") called at /tmp/apache2buddy.pl line 2806 ```
richardforth commented 1 year ago

Ok ., its not really designed to run in docker but if you must run apache2buddy in docker then the container MUST be run with additional privileges otherwise it cant read the memory usage.

You can read about it here.

https://github.com/richardforth/apache2buddy/wiki/Docker-fun-and-games