From 6525ca5f94a9d71336d7c4e7e8f20878d46a44d1 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Sat, 22 Oct 2022 01:18:33 +0200 Subject: [PATCH] net/haproxy: add support for Prometheus exporter, closes #2764 --- net/haproxy/pkg-descr | 1 + .../OPNsense/HAProxy/forms/dialogFrontend.xml | 14 +++++++++ .../OPNsense/HAProxy/forms/generalStats.xml | 27 ++++++++++++++++- .../app/models/OPNsense/HAProxy/HAProxy.xml | 30 ++++++++++++++++++- .../templates/OPNsense/HAProxy/haproxy.conf | 21 ++++++++++--- 5 files changed, 87 insertions(+), 6 deletions(-) diff --git a/net/haproxy/pkg-descr b/net/haproxy/pkg-descr index 37b084e82..2bb68861a 100644 --- a/net/haproxy/pkg-descr +++ b/net/haproxy/pkg-descr @@ -10,6 +10,7 @@ Plugin Changelog Added: * add support for req.ssl_hello_type (#2311) +* add support for Prometheus exporter (#2764) Fixed: * fix unix sockets in chrooted environment (#3093) diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogFrontend.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogFrontend.xml index a028a16f1..9f6fb5801 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogFrontend.xml +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/dialogFrontend.xml @@ -211,6 +211,20 @@ checkbox + + frontend.prometheus_enabled + + checkbox + + true + + + frontend.prometheus_path + + text + + true + header diff --git a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml index 6832e1e17..ad63e778e 100644 --- a/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml +++ b/net/haproxy/src/opnsense/mvc/app/controllers/OPNsense/HAProxy/forms/generalStats.xml @@ -5,7 +5,7 @@ haproxy.general.stats.enabled - + checkbox @@ -57,4 +57,29 @@
NOTE: The syntax will not be checked, use at your own risk!
]]>
true + + + header + + + haproxy.general.stats.prometheus_enabled + + checkbox + + + + haproxy.general.stats.prometheus_bind + + select_multiple + + true + + Enter address:port here. Finish with TAB. + + + haproxy.general.stats.prometheus_path + + text + + diff --git a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml index 3be9a91e1..8a81ffce3 100644 --- a/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml +++ b/net/haproxy/src/opnsense/mvc/app/models/OPNsense/HAProxy/HAProxy.xml @@ -1,6 +1,6 @@ //OPNsense/HAProxy - 3.7.0 + 3.8.0 the HAProxy load balancer @@ -376,6 +376,24 @@ N + + 0 + N + + + *:8404 + N + Y + /^((([0-9a-zA-Z._\-\*:\[\]]+:+[0-9]+(-[0-9]+)?|unix@[0-9a-z_\-]+)([,]){0,1}))*/u + lower + Please provide a valid listen address, i.e. 10.0.0.1:8404 or haproxy.example.com:8404. + + + /metrics + N + /^.{1,2048}$/u + Should be a string between 1 and 2048 characters. + @@ -777,6 +795,16 @@ 0 Y + + 0 + N + + + /metrics + N + /^.{1,2048}$/u + Should be a string between 1 and 2048 characters. + Y http-keep-alive diff --git a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf index c6f0ff8dd..d7d910beb 100644 --- a/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf +++ b/net/haproxy/src/opnsense/service/templates/OPNsense/HAProxy/haproxy.conf @@ -1411,6 +1411,9 @@ frontend {{frontend.name}} {% endif %} {% if frontend.forwardFor == '1' and frontend.mode == 'http' %} option forwardfor +{% endif %} +{% if frontend.prometheus_enabled == '1' and frontend.mode == 'http' and frontend.prometheus_path|default("") != "" %} + http-request use-service prometheus-exporter if { path {{frontend.prometheus_path}} } {% endif %} # tuning options {% if frontend.tuning_maxConnections is defined %} @@ -1916,7 +1919,7 @@ peers {{peers_name}} {# STATISTICS #} {# ############################### #} -{%- if helpers.exists('OPNsense.HAProxy.general.stats') and OPNsense.HAProxy.general.stats.enabled|default("") == "1" %} +{% if helpers.exists('OPNsense.HAProxy.general.stats') and OPNsense.HAProxy.general.stats.enabled|default("") == "1" %} {# # enable local stats #} listen local_statistics bind 127.0.0.1:{{OPNsense.HAProxy.general.stats.port}} @@ -1931,7 +1934,7 @@ listen local_statistics {% endfor %} {% endif %} -{# # remote stats are optional #} +{# # remote stats are optional #} {% if OPNsense.HAProxy.general.stats.remoteEnabled|default("") == "1" %} {% if OPNsense.HAProxy.general.stats.remoteBind|default("") != "" %} listen remote_statistics @@ -1957,8 +1960,18 @@ listen remote_statistics # ERROR: remote statistics disabled, because no listen address was specified {% endif %} {% else %} -# statistics are DISABLED +# remote statistics are DISABLED {% endif %} - +{% else %} +# statistics are DISABLED {% endif %} + +{% if helpers.exists('OPNsense.HAProxy.general.stats') and OPNsense.HAProxy.general.stats.prometheus_enabled|default("") == "1" %} +{# # enable prometheus exporter #} +frontend prometheus_exporter + bind {{OPNsense.HAProxy.general.stats.prometheus_bind}} + mode http + http-request use-service prometheus-exporter if { path {{OPNsense.HAProxy.general.stats.prometheus_path}} } +{% endif %} + {%- endif -%}