From 75c155764f046f000a502ee53067427c0ca5ecc0 Mon Sep 17 00:00:00 2001 From: Aine Date: Fri, 21 Apr 2023 00:57:02 +0300 Subject: [PATCH] proxy metrics of nginx and buscarron --- .../defaults/main.yml | 10 ++++++++ .../tasks/main.yml | 11 ++++----- .../inject_into_nginx_proxy.yml | 24 +++++++++++++++++++ .../inject_into_nginx_proxy.yml | 24 +++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-buscarron/inject_into_nginx_proxy.yml create mode 100644 roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-honoroit/inject_into_nginx_proxy.yml diff --git a/roles/custom/matrix-prometheus-services-proxy-connect/defaults/main.yml b/roles/custom/matrix-prometheus-services-proxy-connect/defaults/main.yml index 30ef2c130..fbdbddf36 100644 --- a/roles/custom/matrix-prometheus-services-proxy-connect/defaults/main.yml +++ b/roles/custom/matrix-prometheus-services-proxy-connect/defaults/main.yml @@ -25,3 +25,13 @@ matrix_prometheus_services_proxy_connect_prometheus_postgres_exporter_metrics_pr # If prometheus_node_exporter_container_http_host_bind_port is set to an IP that is not 0.0.0.0 and a port, that ":" value will be used # Otherwise this value will be empty and you will have to manually configure your NGINX config file. (If you are using the config files generated by this playbook, you will have to edit matrix-domain.conf) matrix_prometheus_services_proxy_connect_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host: "{{ '127.0.0.1' + prometheus_postgres_exporter_container_http_host_bind_port_number_raw if not ':' in prometheus_postgres_exporter_container_http_host_bind_port else (prometheus_postgres_exporter_container_http_host_bind_port if prometheus_postgres_exporter_container_http_host_bind_port.split(':')[0] != '0.0.0.0' else '') }}" + +# Controls whether buscarron metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/buscarron`. +# This will only work take effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. +# See the `matrix-nginx-proxy` role for details about enabling `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. +matrix_prometheus_services_proxy_connect_matrix_bot_buscarron_metrics_proxying_enabled: false + +# Controls whether honoroit metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/buscarron`. +# This will only work take effect if `matrix_nginx_proxy_proxy_matrix_metrics_enabled: true`. +# See the `matrix-nginx-proxy` role for details about enabling `matrix_nginx_proxy_proxy_matrix_metrics_enabled`. +matrix_prometheus_services_proxy_connect_matrix_bot_honoroit_metrics_proxying_enabled: false diff --git a/roles/custom/matrix-prometheus-services-proxy-connect/tasks/main.yml b/roles/custom/matrix-prometheus-services-proxy-connect/tasks/main.yml index ea067bdba..86a660c25 100644 --- a/roles/custom/matrix-prometheus-services-proxy-connect/tasks/main.yml +++ b/roles/custom/matrix-prometheus-services-proxy-connect/tasks/main.yml @@ -17,12 +17,9 @@ block: - when: prometheus_node_exporter_enabled | bool and matrix_prometheus_services_proxy_connect_prometheus_node_exporter_metrics_proxying_enabled | bool ansible.builtin.include_tasks: "{{ role_path }}/tasks/prometheus-node-exporter/inject_into_nginx_proxy.yml" - -- tags: - - setup-all - - setup-nginx-proxy - - install-all - - install-nginx-proxy - block: - when: prometheus_node_exporter_enabled | bool and matrix_prometheus_services_proxy_connect_prometheus_postgres_exporter_metrics_proxying_enabled | bool ansible.builtin.include_tasks: "{{ role_path }}/tasks/prometheus-postgres-exporter/inject_into_nginx_proxy.yml" + - when: matrix_bot_buscarron_enabled | bool and matrix_prometheus_services_proxy_connect_matrix_bot_buscarron_metrics_proxying_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/matrix-bot-buscarron/inject_into_nginx_proxy.yml" + - when: matrix_bot_honoroit_enabled | bool and matrix_prometheus_services_proxy_connect_matrix_bot_honoroit_metrics_proxying_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/matrix-bot-honoroit/inject_into_nginx_proxy.yml" diff --git a/roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-buscarron/inject_into_nginx_proxy.yml b/roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-buscarron/inject_into_nginx_proxy.yml new file mode 100644 index 000000000..73ba2532b --- /dev/null +++ b/roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-buscarron/inject_into_nginx_proxy.yml @@ -0,0 +1,24 @@ +--- + +- name: Generate buscarron metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/buscarron) + ansible.builtin.set_fact: + matrix_prometheus_services_proxy_connect_matrix_bot_buscarron_nginx_metrics_configuration_block: | + location /metrics/buscarron { + {% if matrix_nginx_proxy_enabled | default(False) %} + {# Use the embedded DNS resolver in Docker containers to discover the service #} + resolver 127.0.0.11 valid=5s; + set $backend "matrix-bot-buscarron:8080"; + proxy_pass http://$backend/metrics; + {% else %} + return 404 "matrix-nginx-proxy is disabled and no host port was bound to the container, so metrics are unavailable"; + {% endif %} + } + +- name: Register buscarron metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/buscarron) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | + {{ + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + + + [matrix_prometheus_services_proxy_connect_matrix_bot_buscarron_nginx_metrics_configuration_block] + }} diff --git a/roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-honoroit/inject_into_nginx_proxy.yml b/roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-honoroit/inject_into_nginx_proxy.yml new file mode 100644 index 000000000..2476e66d4 --- /dev/null +++ b/roles/custom/matrix-prometheus-services-proxy-connect/tasks/matrix-bot-honoroit/inject_into_nginx_proxy.yml @@ -0,0 +1,24 @@ +--- + +- name: Generate honoroit metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/honoroit) + ansible.builtin.set_fact: + matrix_prometheus_services_proxy_connect_matrix_bot_honoroit_nginx_metrics_configuration_block: | + location /metrics/honoroit { + {% if matrix_nginx_proxy_enabled | default(False) %} + {# Use the embedded DNS resolver in Docker containers to discover the service #} + resolver 127.0.0.11 valid=5s; + set $backend "matrix-bot-honoroit:8080"; + proxy_pass http://$backend/metrics; + {% else %} + return 404 "matrix-nginx-proxy is disabled and no host port was bound to the container, so metrics are unavailable"; + {% endif %} + } + +- name: Register honoroit metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/honoroit) + ansible.builtin.set_fact: + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | + {{ + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + + + [matrix_prometheus_services_proxy_connect_matrix_bot_honoroit_nginx_metrics_configuration_block] + }}