1
0
Fork 0

Change statistics

This commit is contained in:
Joao M 2022-08-18 04:00:52 +00:00
parent e20f241ab4
commit e6d5842098
7 changed files with 59 additions and 33 deletions

View file

@ -46,15 +46,15 @@ The mapping to `/var/run/docker.sock` is necessary to discover the docker contai
The environment variables will setup the HAProxy. The environment variables will setup the HAProxy.
| Environment Variable | Description | | Environment Variable | Description |
|-------------------------------|-------------------------------------------------------------------------------| |-------------------------------|---------------------------------------------------------------------------------------------------------------|
| EASYHAPROXY_DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` | | EASYHAPROXY_DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` |
| EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search for matching resources. Default: `easyhaproxy`. | | EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search for matching resources. Default: `easyhaproxy`. |
| EASYHAPROXY_LETSENCRYPT_EMAIL | (Optional) The email will be used to request the certificate to Letsencrypt | | EASYHAPROXY_LETSENCRYPT_EMAIL | (Optional) The email will be used to request the certificate to Letsencrypt |
| EASYHAPROXY_SSL_MODE | (Optional) `STRICT` supports only the most recent TLS version; `DEFAULT` good SSL integration with recent browsers; `LOOSE` supports all old SSL protocols for old browsers (not recommended). | | EASYHAPROXY_SSL_MODE | (Optional) `STRICT` supports only the most recent TLS version; `DEFAULT` good SSL integration with recent browsers; `LOOSE` supports all old SSL protocols for old browsers (not recommended). |
| HAPROXY_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` | | HAPROXY_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` |
| HAPROXY_PASSWORD | The HAProxy password to the statistics. If not set, it will disable stats. | | HAPROXY_PASSWORD | (Optional) The HAProxy password to the statistics. If not set, statistics will be available with no password |
| HAPROXY_STATS_PORT | (Optional) The HAProxy port to the statistics. Default: `1936` | | HAPROXY_STATS_PORT | (Optional) The HAProxy port to the statistics. Default: `1936`. If set to `false`, disable statistics |
| HAPROXY_CUSTOMERRORS | (Optional) If HAProxy will use custom HTML errors. true/false. Default: false | | HAPROXY_CUSTOMERRORS | (Optional) If HAProxy will use custom HTML errors. true/false. Default: `false` |
The environment variable `EASYHAPROXY_DISCOVER` will define where is located your containers (see below for more details): The environment variable `EASYHAPROXY_DISCOVER` will define where is located your containers (see below for more details):
@ -258,7 +258,7 @@ Caveats:
You must expose some ports on the EasyHAProxy container and in the firewall. However, you don't need to expose the other container ports because EasyHAProxy will handle that. You must expose some ports on the EasyHAProxy container and in the firewall. However, you don't need to expose the other container ports because EasyHAProxy will handle that.
- The ports `80` and `443`. - The ports `80` and `443`.
- If you enable the HAProxy statistics, you must also expose the port defined in `HAPROXY_STATS_PORT` environment variable. - If you enable the HAProxy statistics, you must also expose the port defined in `HAPROXY_STATS_PORT` environment variable (default 1936). Be aware that statististics are enabled by default with no password.
- Every port defined in `easyhaproxy.[definitions].port` also should be exposed. - Every port defined in `easyhaproxy.[definitions].port` also should be exposed.
e.g. e.g.

View file

@ -26,23 +26,23 @@ defaults
errorfile 504 /etc/haproxy/errors-custom/504.http errorfile 504 /etc/haproxy/errors-custom/504.http
{% endif %} {% endif %}
{% if "stats" in data %} {% set data_stats = data["stats"] | default({}) %}
{% if data_stats["port"] | default(1936) | int > 0 %}
frontend stats frontend stats
bind *:{{ data["stats"]["port"] | default(1936) }} bind *:{{ data_stats["port"] | default(1936) }}
mode http mode http
stats enable stats enable
stats hide-version stats hide-version
stats realm Haproxy\ Statistics stats realm Haproxy\ Statistics
stats uri / stats uri /
stats auth {{ data["stats"]["username"] }}:{{ data["stats"]["password"] }} {% if data_stats["password"] | default("") != "" %}
# acl is_proxystats hdr(host) -i some.host.com stats auth {{ data_stats["username"] | default("admin") }}:{{ data_stats["password"] }}
# default_backend srv_stats {% endif %}
# use_backend srv_stats if is_proxystats
default_backend srv_stats default_backend srv_stats
backend srv_stats backend srv_stats
mode http mode http
server Local 127.0.0.1:{{ data["stats"]["port"] | default(1936) }} server Local 127.0.0.1:{{ data_stats["port"] | default(1936) }}
{% endif %} {% endif %}
{% for o in data["easymapping"] -%} {% for o in data["easymapping"] -%}
{% set mode = o["mode"] or "http" %} {% set mode = o["mode"] or "http" %}

View file

@ -36,9 +36,6 @@ frontend stats
stats realm Haproxy\ Statistics stats realm Haproxy\ Statistics
stats uri / stats uri /
stats auth admin:password stats auth admin:password
# acl is_proxystats hdr(host) -i some.host.com
# default_backend srv_stats
# use_backend srv_stats if is_proxystats
default_backend srv_stats default_backend srv_stats
backend srv_stats backend srv_stats

View file

@ -36,9 +36,6 @@ frontend stats
stats realm Haproxy\ Statistics stats realm Haproxy\ Statistics
stats uri / stats uri /
stats auth joe:s3cr3t stats auth joe:s3cr3t
# acl is_proxystats hdr(host) -i some.host.com
# default_backend srv_stats
# use_backend srv_stats if is_proxystats
default_backend srv_stats default_backend srv_stats
backend srv_stats backend srv_stats

View file

@ -19,6 +19,18 @@ defaults
timeout client 10s timeout client 10s
timeout server 10m timeout server 10m
frontend stats
bind *:1936
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
default_backend srv_stats
backend srv_stats
mode http
server Local 127.0.0.1:1936
backend letsencrypt_backend backend letsencrypt_backend
mode http mode http

View file

@ -36,9 +36,6 @@ frontend stats
stats realm Haproxy\ Statistics stats realm Haproxy\ Statistics
stats uri / stats uri /
stats auth admin:test123 stats auth admin:test123
# acl is_proxystats hdr(host) -i some.host.com
# default_backend srv_stats
# use_backend srv_stats if is_proxystats
default_backend srv_stats default_backend srv_stats
backend srv_stats backend srv_stats

View file

@ -19,7 +19,10 @@ def test_parser_doesnt_crash():
line_list = load_fixture("no-services") line_list = load_fixture("no-services")
result = { result = {
"customerrors": False "customerrors": False,
"stats": {
"port": "false"
}
} }
cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER) cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER)
@ -38,6 +41,9 @@ def test_parser_finds_services():
"customerrors": False, "customerrors": False,
"letsencrypt": { "letsencrypt": {
"email": LETSENCRYPT_EMAIL "email": LETSENCRYPT_EMAIL
},
"stats": {
"port": 0
} }
} }
@ -65,6 +71,9 @@ def test_parser_finds_services_changed_label():
"lookup_label": "haproxy", "lookup_label": "haproxy",
"letsencrypt": { "letsencrypt": {
"email": LETSENCRYPT_EMAIL "email": LETSENCRYPT_EMAIL
},
"stats": {
"port": 0
} }
} }
@ -91,6 +100,9 @@ def test_parser_finds_services_raw():
"customerrors": False, "customerrors": False,
"letsencrypt": { "letsencrypt": {
"email": LETSENCRYPT_EMAIL "email": LETSENCRYPT_EMAIL
},
"stats": {
"port": 0
} }
} }
@ -277,7 +289,10 @@ def test_parser_tcp():
line_list = load_fixture("services-tcp") line_list = load_fixture("services-tcp")
result = { result = {
"customerrors": False "customerrors": False,
"stats": {
"port": 0
}
} }
cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER) cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER)
@ -294,7 +309,10 @@ def test_parser_multi_containers():
line_list = load_fixture("services-multi-containers") line_list = load_fixture("services-multi-containers")
result = { result = {
"customerrors": False "customerrors": False,
"stats": {
"port": 0
}
} }
cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER) cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER)
@ -334,7 +352,10 @@ def test_parser_redirect_ssl():
result = { result = {
"customerrors": False, "customerrors": False,
"ssl_mode": "loose" "ssl_mode": "loose",
"stats": {
"port": 0
}
} }
cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER) cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER)
@ -352,7 +373,10 @@ def test_parser_ssl_strict():
result = { result = {
"customerrors": False, "customerrors": False,
"ssl_mode": "strict" "ssl_mode": "strict",
"stats": {
"port": False
}
} }
cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER) cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER)
@ -369,7 +393,7 @@ def test_parser_ssl_loose():
result = { result = {
"customerrors": False, "customerrors": False,
"ssl_mode": "loose" "ssl_mode": "loose",
} }
cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER) cfg = easymapping.HaproxyConfigGenerator(result, CERTS_FOLDER)
@ -387,7 +411,6 @@ def test_parser_ssl_letsencrypt():
result = { result = {
"customerrors": True, "customerrors": True,
"stats": { "stats": {
"username": "admin",
"password": "password" "password": "password"
}, },
"letsencrypt": { "letsencrypt": {