From 9a887ca4206f74f6a2e1c6f556f0fcedb5417064 Mon Sep 17 00:00:00 2001 From: Tim Jespers Date: Thu, 12 Sep 2019 14:54:44 +0200 Subject: [PATCH 1/2] Check for the exact option matches while grepping Signed-off-by: Tim Jespers --- php-fpm-healthcheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php-fpm-healthcheck b/php-fpm-healthcheck index d8bf4b5..aca609f 100755 --- a/php-fpm-healthcheck +++ b/php-fpm-healthcheck @@ -77,7 +77,7 @@ get_fpm_status() { check_fpm_health_by() { OPTION=$(echo "$1" | sed 's/--//g; s/-/ /g;') VALUE_EXPECTED="$2"; - VALUE_ACTUAL=$(echo "$FPM_STATUS" | grep "^$OPTION" | cut -d: -f2 | sed 's/ //g') + VALUE_ACTUAL=$(echo "$FPM_STATUS" | grep "^$OPTION:" | cut -d: -f2 | sed 's/ //g') if test "$VERBOSE" = 1; then printf "'%s' value '%s' and expected is less than '%s'\\n" "$OPTION" "$VALUE_ACTUAL" "$VALUE_EXPECTED"; fi; From 0c875052bdda886bf328902afd45a0372892de19 Mon Sep 17 00:00:00 2001 From: Tim Jespers Date: Thu, 12 Sep 2019 15:44:36 +0200 Subject: [PATCH 2/2] Update docs & added testcase for queue-len vars Signed-off-by: Tim Jespers --- README.md | 4 ++-- test/testinfra/test_metrics.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a899d0d..e22f8af 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ $ echo $? And you can also check if you have more than `10` processes in the queue: ```console -$ php-fpm-healthcheck --accepted-conn=3000 --listen-queue-len=10 +$ php-fpm-healthcheck --accepted-conn=3000 --listen-queue=10 $ echo $? 0 ``` @@ -155,7 +155,7 @@ More and more people are looking for health checks on kubernetes for php-fpm, he exec: command: - php-fpm-healthcheck - - --listen-queue-len=10 # fails if there are more than 10 processes waiting in the fpm queue + - --listen-queue=10 # fails if there are more than 10 processes waiting in the fpm queue - --accepted-conn=5000 # fails after fpm has served more than 5k requests, this will force the pod to reset, use with caution initialDelaySeconds: 0 periodSeconds: 10 diff --git a/test/testinfra/test_metrics.py b/test/testinfra/test_metrics.py index 10c0a56..f4df171 100644 --- a/test/testinfra/test_metrics.py +++ b/test/testinfra/test_metrics.py @@ -22,3 +22,11 @@ def test_metric_accepted_conn(host): assert "Trying to connect to php-fpm via:" in cmd.stdout assert "status output:" in cmd.stdout assert "pool:" in cmd.stdout + +@pytest.mark.php_fpm +def test_listen_queue_len_and_listen_queue_vars_are_parsed_correctly(host): + cmd = host.run("php-fpm-healthcheck --verbose --listen-queue=5 --listen-queue-len=256") + assert cmd.rc == 0 + assert "Trying to connect to php-fpm via:" in cmd.stdout + assert "'listen queue' value '0' and expected is less than '5" in cmd.stdout + assert "'listen queue len' value '128' and expected is less than '256'" in cmd.stdout