Skip to content

Commit 145acfe

Browse files
authored
Merge pull request #14 from renatomefi/improve/add-all-status
Add all metrics from PHP fpm status page
2 parents c760908 + 602525b commit 145acfe

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

php-fpm-healthcheck

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
#
3030
# Metric options, fails in case the CURRENT VALUE is bigger than the GIVEN VALUE
3131
# --accepted-conn=n
32-
# --listen-queue-len=n
32+
# --listen-queue=n
33+
# --max-listen-queue=n
34+
# --idle-processes=n
3335
# --active-processes=n
36+
# --total-processes=n
37+
# --max-active-processes=n
38+
# --max-children-reached=n
3439
# --slow-requests=n
3540
#
3641

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

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

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

112-
if ! GETOPT=$(getopt -o v --long verbose,accepted-conn:,listen-queue-len:,active-processes:,slow-requests: -n 'php-fpm-healthcheck' -- "$@"); then
117+
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
113118
>&2 echo "Invalid options, terminating." ; exit 3
114119
fi;
115120

test/testinfra/test_execution.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ def test_valid_with_non_integer_value_exits_properly(host):
2020
assert cmd.rc == 3
2121
assert "option value must be an integer" in cmd.stderr
2222

23+
@pytest.mark.php_fpm
24+
def test_all_available_options_at_once(host):
25+
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")
26+
assert cmd.rc == 0
27+
28+
@pytest.mark.php_fpm
29+
@pytest.mark.parametrize("option", [
30+
"--accepted-conn",
31+
"--listen-queue",
32+
"--max-listen-queue",
33+
"--idle-processes",
34+
"--active-processes",
35+
"--total-processes",
36+
"--max-active-processes",
37+
"--max-children-reached",
38+
"--slow-requests",
39+
])
40+
def test_all_available_options(host, option):
41+
cmd = host.run("php-fpm-healthcheck --verbose {0}=1000".format(option))
42+
assert cmd.rc == 0
43+
assert "value" in cmd.stdout
44+
assert "and expected is less than '1000'" in cmd.stdout
45+
2346
@pytest.mark.alpine
2447
def test_missing_fcgi_apk(host):
2548
host.run("apk del fcgi")

test/testinfra/test_metrics.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
4+
def test_metric_fail_accepted_conn(host):
5+
cmd = host.run("php-fpm-healthcheck --accepted-conn=0")
6+
assert cmd.rc == 1
7+
assert "'accepted conn' value '1' is greater than expected '0'" in cmd.stderr
8+
9+
@pytest.mark.php_fpm
10+
def test_metric_fail_accepted_conn_with_other_metrics(host):
11+
cmd = host.run("php-fpm-healthcheck --verbose --listen-queue=10 --max-active-processes=10 --accepted-conn=0")
12+
assert cmd.rc == 1
13+
assert "'accepted conn' value '2' is greater than expected '0'" in cmd.stderr
14+
assert "'listen queue' value" in cmd.stdout
15+
assert "'max active processes' value" in cmd.stdout
16+
317
@pytest.mark.php_fpm
418
def test_metric_accepted_conn(host):
519
cmd = host.run("php-fpm-healthcheck -v")

0 commit comments

Comments
 (0)