From 934e4565fe0f71589d15beac538f8da6c6e8bf6b Mon Sep 17 00:00:00 2001 From: "alessandro.ceglie" Date: Mon, 18 Oct 2021 11:15:11 +0200 Subject: [PATCH 1/2] added enviroment variable to set stats refresh timing by setting env STATS_REFRESH. --- haproxy/Readme.md | 4 ++++ haproxy/docker-entrypoint.sh | 1 + haproxy/src/configure.py | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/haproxy/Readme.md b/haproxy/Readme.md index 8ca5582..4eaac52 100644 --- a/haproxy/Readme.md +++ b/haproxy/Readme.md @@ -75,6 +75,9 @@ that served the page changes, as HAProxy switches between them. The stats page can be accessed at http://localhost:1936 where you have to log in using the `STATS_AUTH` authentication details (default `admin:admin`). +You may want to set `STATS_REFRESH` option to let the statistics page auto update +i.e `STATS_REFRESH="5s"` to update every five seconds (default `0s`: no refresh) + Note that it may take **up to one minute** until backends are plugged-in due to the minimum possible `DNS_TTL`. @@ -129,6 +132,7 @@ either when running the container or in a `docker-compose.yml` file. * `STATS_PORT` The port to bind statistics to - default `1936` * `STATS_AUTH` The authentication details (written as `user:password` for the statistics page - default `admin:admin` + * `STATS_REFRESH` Refresh timing for the statistics page - default `0s` (no refresh) * `FRONTEND_NAME` The label of the frontend - default `http-frontend` * `FRONTEND_PORT` The port to bind the frontend to - default `5000` * `FRONTEND_MODE` Frontend mode - default `http` or `BACKENDS_MODE` if declared diff --git a/haproxy/docker-entrypoint.sh b/haproxy/docker-entrypoint.sh index 16b957b..c41dd1b 100755 --- a/haproxy/docker-entrypoint.sh +++ b/haproxy/docker-entrypoint.sh @@ -54,6 +54,7 @@ if ! test -e /usr/local/etc/haproxy/haproxy.cfg; then if [ -n "$SERVICE_NAMES" ]; then echo "export SERVICE_NAMES=\"$SERVICE_NAMES\"" >> /etc/environment; fi if [ -n "$STATS_AUTH" ]; then echo "export STATS_AUTH=\"$STATS_AUTH\"" >> /etc/environment; fi if [ -n "$STATS_PORT" ]; then echo "export STATS_PORT=\"$STATS_PORT\"" >> /etc/environment; fi + if [ -n "$STATS_REFRESH" ]; then echo "export STATS_REFRESH=\"$STATS_REFRESH\"" >> /etc/environment; fi if [ -n "$TIMEOUT_CLIENT" ]; then echo "export TIMEOUT_CLIENT=\"$TIMEOUT_CLIENT\"" >> /etc/environment; fi if [ -n "$TIMEOUT_CONNECT" ]; then echo "export TIMEOUT_CONNECT=\"$TIMEOUT_CONNECT\"" >> /etc/environment; fi if [ -n "$TIMEOUT_SERVER" ]; then echo "export TIMEOUT_SERVER=\"$TIMEOUT_SERVER\"" >> /etc/environment; fi diff --git a/haproxy/src/configure.py b/haproxy/src/configure.py index aec0c80..9d70290 100644 --- a/haproxy/src/configure.py +++ b/haproxy/src/configure.py @@ -20,6 +20,7 @@ PROXY_PROTOCOL_ENABLED = (os.environ.get('PROXY_PROTOCOL_ENABLED', 'false').lower() == "true") STATS_PORT = os.environ.get('STATS_PORT', '1936') STATS_AUTH = os.environ.get('STATS_AUTH', 'admin:admin') +STATS_REFRESH = os.environ.get('STATS_REFRESH', '0s') BACKENDS = os.environ.get('BACKENDS', '').split(' ') BACKENDS_PORT = os.environ.get('BACKENDS_PORT', '80') BACKENDS_MODE = os.environ.get('BACKENDS_MODE', FRONTEND_MODE) @@ -44,6 +45,7 @@ stats uri / stats hide-version stats auth $auth + stats refresh $refresh """) frontend_conf = Template(""" @@ -235,7 +237,7 @@ configuration.write( listen_conf.substitute( - port=STATS_PORT, auth=STATS_AUTH + port=STATS_PORT, auth=STATS_AUTH, refresh=STATS_REFRESH ) ) From 00387eec96577685538a964131a01c89b350b67c Mon Sep 17 00:00:00 2001 From: "alessandro.ceglie" Date: Mon, 18 Oct 2021 11:24:32 +0200 Subject: [PATCH 2/2] sanity code --- haproxy/src/configure.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/haproxy/src/configure.py b/haproxy/src/configure.py index 9d70290..666ea0c 100644 --- a/haproxy/src/configure.py +++ b/haproxy/src/configure.py @@ -237,7 +237,9 @@ configuration.write( listen_conf.substitute( - port=STATS_PORT, auth=STATS_AUTH, refresh=STATS_REFRESH + port=STATS_PORT, + auth=STATS_AUTH, + refresh=STATS_REFRESH ) )