Skip to content

Commit

Permalink
Enable all possible status
Browse files Browse the repository at this point in the history
Fixes #3
It's now possible to healthcheck against all metrics exposed by php-fpm
status page.
  • Loading branch information
renatomefi committed Sep 18, 2018
1 parent c760908 commit b18aaf9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
11 changes: 8 additions & 3 deletions php-fpm-healthcheck
Expand Up @@ -29,8 +29,13 @@
#
# Metric options, fails in case the CURRENT VALUE is bigger than the GIVEN VALUE
# --accepted-conn=n
# --listen-queue-len=n
# --listen-queue=n
# --max-listen-queue=n
# --idle-processes=n
# --active-processes=n
# --total-processes=n
# --max-active-processes=n
# --max-children-reached=n
# --slow-requests=n
#

Expand Down Expand Up @@ -74,7 +79,7 @@ check_fpm_health_by() {
VALUE_EXPECTED="$2";
VALUE_ACTUAL=$(echo "$FPM_STATUS" | grep "^$OPTION" | cut -d: -f2 | sed 's/ //g')

if test "$VERBOSE" = 1; then printf "'%s' value is: '%s' and expected is less than: '%s'\\n" "$OPTION" "$VALUE_ACTUAL" "$VALUE_EXPECTED"; fi;
if test "$VERBOSE" = 1; then printf "'%s' value '%s' and expected is less than '%s'\\n" "$OPTION" "$VALUE_ACTUAL" "$VALUE_EXPECTED"; fi;

if test "$VALUE_ACTUAL" -gt "$VALUE_EXPECTED"; then
>&2 printf "'%s' value '%s' is greater than expected '%s'\\n" "$OPTION" "$VALUE_ACTUAL" "$VALUE_EXPECTED";
Expand Down Expand Up @@ -109,7 +114,7 @@ check_fpm_health() {
done
}

if ! GETOPT=$(getopt -o v --long verbose,accepted-conn:,listen-queue-len:,active-processes:,slow-requests: -n 'php-fpm-healthcheck' -- "$@"); then
if ! GETOPT=$(getopt -o v --long verbose,accepted-conn:,listen-queue:,max-listen-queue:,listen-queue-len:,idle-processes:,active-processes:,total-processes:,max-active-processes:,max-children-reached:,slow-requests: -n 'php-fpm-healthcheck' -- "$@"); then
>&2 echo "Invalid options, terminating." ; exit 3
fi;

Expand Down
23 changes: 23 additions & 0 deletions test/testinfra/test_execution.py
Expand Up @@ -20,6 +20,29 @@ def test_valid_with_non_integer_value_exits_properly(host):
assert cmd.rc == 3
assert "option value must be an integer" in cmd.stderr

@pytest.mark.php_fpm
def test_all_available_options_at_once(host):
cmd = host.run("php-fpm-healthcheck --accepted-conn=1000 --listen-queue=1000 --max-listen-queue=1000 --listen-queue-len=1000 --idle-processes=1000 --active-processes=1000 --total-processes=1000 --max-active-processes=1000 --max-children-reached=1000 --slow-requests=1000")
assert cmd.rc == 0

@pytest.mark.php_fpm
@pytest.mark.parametrize("option", [
"--accepted-conn",
"--listen-queue",
"--max-listen-queue",
"--idle-processes",
"--active-processes",
"--total-processes",
"--max-active-processes",
"--max-children-reached",
"--slow-requests",
])
def test_all_available_options(host, option):
cmd = host.run("php-fpm-healthcheck --verbose {0}=1000".format(option))
assert cmd.rc == 0
assert "value" in cmd.stdout
assert "and expected is less than '1000'" in cmd.stdout

@pytest.mark.alpine
def test_missing_fcgi_apk(host):
host.run("apk del fcgi")
Expand Down

0 comments on commit b18aaf9

Please sign in to comment.