Merge pull request #3168 from fraenki/haproxy_312a

net/haproxy: add support for Prometheus exporter
This commit is contained in:
Frank Wall 2022-10-22 01:19:56 +02:00 committed by GitHub
commit 3806468af6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 6 deletions

View file

@ -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)

View file

@ -211,6 +211,20 @@
<type>checkbox</type>
<help><![CDATA[Enable insertion of the X-Forwarded-For header to requests sent to servers.]]></help>
</field>
<field>
<id>frontend.prometheus_enabled</id>
<label>Prometheus Enabled</label>
<type>checkbox</type>
<help><![CDATA[Enable HAProxy's Prometheus exporter.]]></help>
<advanced>true</advanced>
</field>
<field>
<id>frontend.prometheus_path</id>
<label>Prometheus Path</label>
<type>text</type>
<help><![CDATA[The path where the Prometheus exporter can be accessed.]]></help>
<advanced>true</advanced>
</field>
<field>
<label>Basic Authentication</label>
<type>header</type>

View file

@ -5,7 +5,7 @@
</field>
<field>
<id>haproxy.general.stats.enabled</id>
<label>Stats enabled</label>
<label>Enabled</label>
<type>checkbox</type>
<help><![CDATA[Enable HAProxy's statistics page.]]></help>
</field>
@ -57,4 +57,29 @@
<help><![CDATA[These lines will be added to the statistics settings of to the HAProxy configuration file.<br/><div class="text-info"><b>NOTE:</b> The syntax will not be checked, use at your own risk!</div>]]></help>
<advanced>true</advanced>
</field>
<field>
<label>Prometheus Exporter</label>
<type>header</type>
</field>
<field>
<id>haproxy.general.stats.prometheus_enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help><![CDATA[Enable HAProxy's Prometheus exporter.]]></help>
</field>
<field>
<id>haproxy.general.stats.prometheus_bind</id>
<label>Listen addresses</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
<help><![CDATA[Configure listen addresses for the prometheus exporter, i.e. 10.0.0.1:8404 or haproxy.example.com:8404. Use TAB key to complete typing a listen address.]]></help>
<hint>Enter address:port here. Finish with TAB.</hint>
</field>
<field>
<id>haproxy.general.stats.prometheus_path</id>
<label>Path</label>
<type>text</type>
<help><![CDATA[The path where the Prometheus exporter can be accessed.]]></help>
</field>
</form>

View file

@ -1,6 +1,6 @@
<model>
<mount>//OPNsense/HAProxy</mount>
<version>3.7.0</version>
<version>3.8.0</version>
<description>the HAProxy load balancer</description>
<items>
<general>
@ -376,6 +376,24 @@
<customOptions type="TextField">
<Required>N</Required>
</customOptions>
<prometheus_enabled type="BooleanField">
<default>0</default>
<Required>N</Required>
</prometheus_enabled>
<prometheus_bind type="CSVListField">
<default>*:8404</default>
<Required>N</Required>
<multiple>Y</multiple>
<mask>/^((([0-9a-zA-Z._\-\*:\[\]]+:+[0-9]+(-[0-9]+)?|unix@[0-9a-z_\-]+)([,]){0,1}))*/u</mask>
<ChangeCase>lower</ChangeCase>
<ValidationMessage>Please provide a valid listen address, i.e. 10.0.0.1:8404 or haproxy.example.com:8404.</ValidationMessage>
</prometheus_bind>
<prometheus_path type="TextField">
<default>/metrics</default>
<Required>N</Required>
<mask>/^.{1,2048}$/u</mask>
<ValidationMessage>Should be a string between 1 and 2048 characters.</ValidationMessage>
</prometheus_path>
</stats>
<cache>
<enabled type="BooleanField">
@ -777,6 +795,16 @@
<default>0</default>
<Required>Y</Required>
</forwardFor>
<prometheus_enabled type="BooleanField">
<default>0</default>
<Required>N</Required>
</prometheus_enabled>
<prometheus_path type="TextField">
<default>/metrics</default>
<Required>N</Required>
<mask>/^.{1,2048}$/u</mask>
<ValidationMessage>Should be a string between 1 and 2048 characters.</ValidationMessage>
</prometheus_path>
<connectionBehaviour type="OptionField">
<Required>Y</Required>
<default>http-keep-alive</default>

View file

@ -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 -%}