Switch from matrix-prometheus-postgres-exporter to an external prometheus_postgres_exporter role
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
---
|
||||
# matrix-prometheus-postgres-exporter is an Prometheus exporter for postgres metrics
|
||||
# Project source code URL: https://github.com/prometheus-community/postgres_exporter
|
||||
|
||||
matrix_prometheus_postgres_exporter_enabled: false
|
||||
|
||||
matrix_prometheus_postgres_exporter_version: v0.11.1
|
||||
matrix_prometheus_postgres_exporter_port: 9187
|
||||
|
||||
matrix_prometheus_postgres_exporter_docker_image: "{{ matrix_prometheus_postgres_exporter_docker_image_name_prefix }}prometheuscommunity/postgres-exporter:{{ matrix_prometheus_postgres_exporter_version }}"
|
||||
matrix_prometheus_postgres_exporter_docker_image_name_prefix: "quay.io/"
|
||||
matrix_prometheus_postgres_exporter_docker_image_force_pull: "{{ matrix_prometheus_postgres_exporter_docker_image.endswith(':latest') }}"
|
||||
|
||||
# A list of extra arguments to pass to the container
|
||||
matrix_prometheus_postgres_exporter_container_extra_arguments: ["-e PG_EXPORTER_AUTO_DISCOVER_DATABASES=true",
|
||||
"-e PG_EXPORTER_WEB_LISTEN_ADDRESS=\":{{ matrix_prometheus_postgres_exporter_port }}\"",
|
||||
"-e DATA_SOURCE_NAME=\"postgresql://{{ matrix_prometheus_postgres_exporter_database_username }}:{{ matrix_prometheus_postgres_exporter_database_password }}@{{ matrix_prometheus_postgres_exporter_database_hostname }}:5432/{{ matrix_prometheus_postgres_exporter_database_name }}?sslmode=disable\""]
|
||||
|
||||
# List of systemd services that matrix-prometheus-postgres-exporter.service depends on
|
||||
matrix_prometheus_postgres_exporter_systemd_required_services_list: ['docker.service']
|
||||
|
||||
# List of systemd services that matrix-prometheus-postgres-exporter.service wants
|
||||
matrix_prometheus_postgres_exporter_systemd_wanted_services_list: []
|
||||
|
||||
# details for connecting to the database
|
||||
matrix_prometheus_postgres_exporter_database_username: 'matrix_prometheus_postgres_exporter'
|
||||
matrix_prometheus_postgres_exporter_database_password: 'some-password'
|
||||
matrix_prometheus_postgres_exporter_database_hostname: ''
|
||||
matrix_prometheus_postgres_exporter_database_port: 5432
|
||||
matrix_prometheus_postgres_exporter_database_name: 'matrix_prometheus_postgres_exporter'
|
||||
|
||||
# Controls whether postgres-exporter metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/postgres-exporter`.
|
||||
# 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_postgres_exporter_metrics_proxying_enabled: false
|
||||
|
||||
# Controls whether the matrix-prometheus container exposes its HTTP port (tcp/9187 in the container).
|
||||
#
|
||||
# Takes an "<ip>:<port>" value (e.g. "127.0.0.1:9187"), just a port number or an empty string to not expose.
|
||||
#
|
||||
# You likely don't need to do this. See `matrix_prometheus_postgres_exporter_metrics_proxying_enabled`.
|
||||
#
|
||||
# Official recommendations are to run this container with `--net=host`,
|
||||
# but we don't do that, since it:
|
||||
# - likely exposes the metrics web server way too publicly (before applying https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/1008)
|
||||
# - or listens on a loopback interface only (--net=host and 127.0.0.1:9187), which is not reachable from another container (like `matrix-prometheus`)
|
||||
#
|
||||
# Using `--net=host` and binding to Docker's `matrix` bridge network may be a solution to both,
|
||||
# but that's trickier to accomplish and won't necessarily work (hasn't been tested).
|
||||
#
|
||||
# Not using `--net=host` means that our network statistic reports are likely broken (inaccurate),
|
||||
# because node-exporter can't see all interfaces, etc.
|
||||
# For now, we'll live with that, until someone develops a better solution.
|
||||
matrix_prometheus_postgres_exporter_container_http_host_bind_port: ''
|
||||
|
||||
# If you are supplying your own NGINX proxy but want to use the provided exporters you will have to supply an "<ip>:<port>" value for the containers to bind to on your host.
|
||||
# If matrix_prometheus_postgres_exporter_container_http_host_bind_port is set to just a port number, this will default to "127.0.0.1:<port>"
|
||||
# If matrix_prometheus_postgres_exporter_container_http_host_bind_port is set to an IP that is not 0.0.0.0 and a port, that "<ip>:<port>" 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_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host: "{{ '127.0.0.1' + matrix_prometheus_postgres_exporter_container_http_host_bind_port_number_raw if not ':' in matrix_prometheus_postgres_exporter_container_http_host_bind_port else (matrix_prometheus_postgres_exporter_container_http_host_bind_port if matrix_prometheus_postgres_exporter_container_http_host_bind_port.split(':')[0] != '0.0.0.0' else '') }}"
|
||||
|
||||
# matrix_prometheus_postgres_exporter_dashboard_urls contains a list of URLs with Grafana dashboard definitions.
|
||||
# If the Grafana role is enabled, these dashboards will be downloaded.
|
||||
matrix_prometheus_postgres_exporter_dashboard_urls:
|
||||
- "https://grafana.com/api/dashboards/9628/revisions/7/download"
|
@ -1,29 +0,0 @@
|
||||
---
|
||||
|
||||
- block:
|
||||
- when: matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_metrics_proxying_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/inject_into_nginx_proxy.yml"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-nginx-proxy
|
||||
- install-all
|
||||
- install-nginx-proxy
|
||||
|
||||
- block:
|
||||
- when: matrix_prometheus_postgres_exporter_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
|
||||
- when: matrix_prometheus_postgres_exporter_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-prometheus-postgres-exporter
|
||||
- install-all
|
||||
- install-prometheus-postgres-exporter
|
||||
|
||||
- block:
|
||||
- when: not matrix_prometheus_postgres_exporter_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_uninstall.yml"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-prometheus-postgres-exporter
|
@ -1,19 +0,0 @@
|
||||
---
|
||||
|
||||
- name: Ensure matrix-prometheus-postgres-exporter image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_prometheus_postgres_exporter_docker_image }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_prometheus_postgres_exporter_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||||
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_prometheus_postgres_exporter_docker_image_force_pull }}"
|
||||
register: result
|
||||
retries: "{{ devture_playbook_help_container_retries_count }}"
|
||||
delay: "{{ devture_playbook_help_container_retries_delay }}"
|
||||
until: result is not failed
|
||||
|
||||
- name: Ensure matrix-prometheus-postgres-exporter.service installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-prometheus-postgres-exporter.service.j2"
|
||||
dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-prometheus-postgres-exporter.service"
|
||||
mode: 0644
|
||||
register: matrix_prometheus_postgres_exporter_systemd_service_result
|
@ -1,20 +0,0 @@
|
||||
---
|
||||
|
||||
- name: Check existence of matrix-prometheus-postgres-exporter service
|
||||
ansible.builtin.stat:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-prometheus-postgres-exporter.service"
|
||||
register: matrix_prometheus_postgres_exporter_service_stat
|
||||
|
||||
- when: matrix_prometheus_postgres_exporter_service_stat.stat.exists | bool
|
||||
block:
|
||||
- name: Ensure matrix-prometheus-postgres-exporter is stopped
|
||||
ansible.builtin.service:
|
||||
name: matrix-prometheus-postgres-exporter
|
||||
state: stopped
|
||||
enabled: false
|
||||
daemon_reload: true
|
||||
|
||||
- name: Ensure matrix-prometheus-postgres-exporter.service doesn't exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-prometheus-postgres-exporter.service"
|
||||
state: absent
|
@ -1,9 +0,0 @@
|
||||
---
|
||||
|
||||
- name: Fail if required prometheus-postgres-exporter settings not defined
|
||||
ansible.builtin.fail:
|
||||
msg: >
|
||||
You need to define a required configuration setting (`{{ item }}`).
|
||||
when: "vars[item] == ''"
|
||||
with_items:
|
||||
- matrix_prometheus_postgres_exporter_database_hostname
|
@ -1,42 +0,0 @@
|
||||
#jinja2: lstrip_blocks: "True"
|
||||
[Unit]
|
||||
Description=matrix-prometheus-postgres-exporter
|
||||
{% for service in matrix_prometheus_postgres_exporter_systemd_required_services_list %}
|
||||
Requires={{ service }}
|
||||
After={{ service }}
|
||||
{% endfor %}
|
||||
{% for service in matrix_prometheus_postgres_exporter_systemd_wanted_services_list %}
|
||||
Wants={{ service }}
|
||||
{% endfor %}
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
|
||||
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} kill matrix-prometheus-postgres-exporter 2>/dev/null || true'
|
||||
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-prometheus-postgres-exporter 2>/dev/null || true'
|
||||
|
||||
|
||||
ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-prometheus-postgres-exporter \
|
||||
--log-driver=none \
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
|
||||
--cap-drop=ALL \
|
||||
--read-only \
|
||||
{% for arg in matrix_prometheus_postgres_exporter_container_extra_arguments %}
|
||||
{{ arg }} \
|
||||
{% endfor %}
|
||||
--network={{ matrix_docker_network }} \
|
||||
{% if matrix_prometheus_postgres_exporter_container_http_host_bind_port %}
|
||||
-p {{ matrix_prometheus_postgres_exporter_container_http_host_bind_port }}:{{matrix_prometheus_postgres_exporter_port}} \
|
||||
{% endif %}
|
||||
--pid=host \
|
||||
{{ matrix_prometheus_postgres_exporter_docker_image }}
|
||||
|
||||
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} kill matrix-prometheus-postgres-exporter 2>/dev/null || true'
|
||||
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-prometheus-postgres-exporter 2>/dev/null || true'
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
SyslogIdentifier=matrix-prometheus-postgres-exporter
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
|
||||
# `matrix_prometheus_postgres_exporter_container_http_host_bind_port_number_raw` contains the raw port number extracted from `matrix_prometheus_postgres_exporter_container_http_host_bind_port`,
|
||||
# which can contain values like this: ('1234', '127.0.0.1:1234', '0.0.0.0:1234')
|
||||
matrix_prometheus_postgres_exporter_container_http_host_bind_port_number_raw: "{{ '' if matrix_prometheus_postgres_exporter_container_http_host_bind_port == '' else (matrix_prometheus_postgres_exporter_container_http_host_bind_port.split(':')[1] if ':' in matrix_prometheus_postgres_exporter_container_http_host_bind_port else matrix_prometheus_postgres_exporter_container_http_host_bind_port) }}"
|
@ -13,3 +13,15 @@ matrix_prometheus_services_proxy_connect_prometheus_node_exporter_metrics_proxyi
|
||||
# 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 "<ip>:<port>" 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_node_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host: "{{ '127.0.0.1' + prometheus_node_exporter_container_http_host_bind_port_number_raw if not ':' in prometheus_node_exporter_container_http_host_bind_port else (prometheus_node_exporter_container_http_host_bind_port if prometheus_node_exporter_container_http_host_bind_port.split(':')[0] != '0.0.0.0' else '') }}"
|
||||
|
||||
|
||||
# Controls whether postgres-exporter metrics should be proxied (exposed) on `matrix.DOMAIN/metrics/postgres-exporter`.
|
||||
# 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_prometheus_postgres_exporter_metrics_proxying_enabled: false
|
||||
|
||||
# If you are supplying your own NGINX proxy but want to use the provided exporters you will have to supply an "<ip>:<port>" value for the containers to bind to on your host.
|
||||
# If prometheus_node_exporter_container_http_host_bind_port is set to just a port number, this will default to "127.0.0.1:<port>"
|
||||
# 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 "<ip>:<port>" 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 '') }}"
|
||||
|
@ -17,3 +17,12 @@
|
||||
- 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"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-nginx-proxy
|
||||
- install-all
|
||||
- install-nginx-proxy
|
||||
|
@ -1,25 +1,16 @@
|
||||
---
|
||||
|
||||
- name: Fail if matrix-nginx-proxy role already executed
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
Trying to append postgres-exporter's reverse-proxying configuration to matrix-nginx-proxy,
|
||||
but it's pointless since the matrix-nginx-proxy role had already executed.
|
||||
To fix this, please change the order of roles in your playbook,
|
||||
so that the matrix-nginx-proxy role would run after the matrix-prometheus-postgres-exporter role.
|
||||
when: matrix_nginx_proxy_role_executed | default(False) | bool
|
||||
|
||||
- name: Generate postgres-exporter metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/postgres-exporter)
|
||||
ansible.builtin.set_fact:
|
||||
matrix_prometheus_postgres_exporter_nginx_metrics_configuration_block: |
|
||||
matrix_prometheus_services_proxy_connect_postgres_exporter_nginx_metrics_configuration_block: |
|
||||
location /metrics/postgres-exporter {
|
||||
{% 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-prometheus-postgres-exporter:9187";
|
||||
set $backend "{{ prometheus_postgres_exporter_identifier }}:{{ prometheus_postgres_exporter_port }}";
|
||||
proxy_pass http://$backend/metrics;
|
||||
{% elif matrix_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host != '' %}
|
||||
proxy_pass http://{{ matrix_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host }}/metrics;
|
||||
{% elif matrix_prometheus_services_proxy_connect_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host != '' %}
|
||||
proxy_pass http://{{ matrix_prometheus_services_proxy_connect_prometheus_postgres_exporter_matrix_nginx_proxy_not_enabled_proxy_pass_host }}/metrics;
|
||||
{% else %}
|
||||
return 404 "matrix-nginx-proxy is disabled and no host port was bound to the container, so metrics are unavailable";
|
||||
{% endif %}
|
||||
@ -31,5 +22,5 @@
|
||||
{{
|
||||
matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([])
|
||||
+
|
||||
[matrix_prometheus_postgres_exporter_nginx_metrics_configuration_block]
|
||||
[matrix_prometheus_services_proxy_connect_postgres_exporter_nginx_metrics_configuration_block]
|
||||
}}
|
@ -2,3 +2,6 @@
|
||||
|
||||
# Controls if (`matrix_prometheus_node_exporter` -> `prometheus_node_exporter`) validation will run.
|
||||
matrix_playbook_migration_matrix_prometheus_node_exporter_migration_validation_enabled: true
|
||||
|
||||
# Controls if (`matrix_prometheus_postgres_exporter` -> `prometheus_postgres_exporter`) validation will run.
|
||||
matrix_playbook_migration_matrix_prometheus_postgres_exporter_migration_validation_enabled: true
|
||||
|
@ -35,6 +35,7 @@
|
||||
- {'old': 'matrix_common_after_systemd_service_start_wait_for_timeout_seconds', 'new': 'devture_systemd_service_manager_up_verification_delay_seconds'}
|
||||
- {'old': 'matrix_systemd_services_autostart_enabled', 'new': 'devture_systemd_service_manager_services_autostart_enabled'}
|
||||
- {'old': 'matrix_prometheus_node_exporter_metrics_proxying_enabled', 'new': 'matrix_prometheus_services_proxy_connect_prometheus_node_exporter_metrics_proxying_enabled'}
|
||||
- {'old': 'matrix_prometheus_postgres_exporter_metrics_proxying_enabled', 'new': 'matrix_prometheus_services_proxy_connect_prometheus_postgres_exporter_metrics_proxying_enabled'}
|
||||
|
||||
- name: (Deprecation) Catch and report matrix_postgres variables
|
||||
ansible.builtin.fail:
|
||||
@ -64,3 +65,18 @@
|
||||
Please change your configuration (vars.yml) to rename all variables (`matrix_prometheus_node_exporter_` -> `prometheus_node_exporter_`).
|
||||
We found usage of the following variables: {{ matrix_playbook_migration_matrix_prometheus_node_exporter_migration_vars.keys() | join(', ') }}
|
||||
when: "matrix_playbook_migration_matrix_prometheus_node_exporter_migration_vars | length > 0"
|
||||
|
||||
- when: matrix_playbook_migration_matrix_prometheus_postgres_exporter_migration_validation_enabled | bool
|
||||
block:
|
||||
- ansible.builtin.set_fact:
|
||||
matrix_playbook_migration_matrix_prometheus_postgres_exporter_migration_vars: |-
|
||||
{{ vars | dict2items | selectattr('key', 'match', 'matrix_prometheus_postgres_exporter_.*') | list | items2dict }}
|
||||
|
||||
- name: (Deprecation) Catch and report matrix_prometheus_postgres_exporter variables
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
The matrix-prometheus-postgres-exporter role that used to be part of this playbook has been replaced by https://gitlab.com/etke.cc/roles/prometheus_postgres_exporter.
|
||||
The new role is compatible with the old one, but uses different names for its variables.
|
||||
Please change your configuration (vars.yml) to rename all variables (`matrix_prometheus_postgres_exporter_` -> `prometheus_postgres_exporter_`).
|
||||
We found usage of the following variables: {{ matrix_playbook_migration_matrix_prometheus_postgres_exporter_migration_vars.keys() | join(', ') }}
|
||||
when: "matrix_playbook_migration_matrix_prometheus_postgres_exporter_migration_vars | length > 0"
|
||||
|
Reference in New Issue
Block a user