From e51e4ce7a0e14cc473f5554d8146d5346f6a8323 Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Mon, 31 May 2021 16:23:19 +0200 Subject: [PATCH] update exporter conf for mongoDB and mysql --- tasks/mongodb_exporter.yml | 20 +++++++++---------- tasks/postgresql_exporter.yml | 16 ++++----------- ...conf.j2 => prometheus-mongodb-exporter.j2} | 0 .../conf/prometheus-postgres-exporter.j2 | 2 ++ .../prometheus-mongodb-exporter.service.j2 | 2 +- .../prometheus-postgres-exporter.service.j2 | 6 ++++-- 6 files changed, 21 insertions(+), 25 deletions(-) rename templates/conf/{mongodb-exporter.conf.j2 => prometheus-mongodb-exporter.j2} (100%) create mode 100644 templates/conf/prometheus-postgres-exporter.j2 diff --git a/tasks/mongodb_exporter.yml b/tasks/mongodb_exporter.yml index f69baf1..b052182 100644 --- a/tasks/mongodb_exporter.yml +++ b/tasks/mongodb_exporter.yml @@ -53,18 +53,18 @@ notify: - 'prometheus | mongodb exporter | restart service' -- name: 'prometheus | mongodb exporter | configuration' - template: - src: conf/mongodb-exporter.conf.j2 - dest: /etc/mongodb-exporter.conf - owner: root - group: root - mode: 0600 - notify: - - 'prometheus | mongodb exporter | restart service' - - name: 'prometheus | mongodb exporter | configure systemd to use service' systemd: daemon_reload: yes enabled: yes name: prometheus-mongodb-exporter.service + +- name: 'prometheus | mongodb exporter | configuration' + template: + src: conf/prometheus-mongodb-exporter.j2 + dest: /etc/default/prometheus-mongodb-exporter + owner: root + group: root + mode: 0600 + notify: + - 'prometheus | mongodb exporter | restart service' diff --git a/tasks/postgresql_exporter.yml b/tasks/postgresql_exporter.yml index 6beae07..ebf149c 100644 --- a/tasks/postgresql_exporter.yml +++ b/tasks/postgresql_exporter.yml @@ -44,20 +44,12 @@ name: prometheus-postgres-exporter.service - name: 'prometheus | postgres exporter | configuration' - copy: - dest: '/etc/default/prometheus-postgres-exporter' + template: + src: conf/prometheus-postgres-exporter.j2 + dest: /etc/default/prometheus-postgres-exporter owner: root group: root - mode: 0644 - backup: yes - content: | - DATA_SOURCE_NAME='postgresql://{{ prometheus_exporter_postgresql_user }}:{{ prometheus_exporter_postgresql_password }}@{{ prometheus_exporter_postgresql_host }}:{{prometheus_exporter_postgresql_port }}/'' - ARGS='' - when: - - prometheus_postgres_exporter_user is defined - - prometheus_postgres_exporter_password is defined - - prometheus_postgres_exporter_host is defined - - prometheus_postgres_exporter_port is defined + mode: 0600 register: prometheu_postgres_exporter_configuration notify: - 'prometheus | postgres exporter | restart service' diff --git a/templates/conf/mongodb-exporter.conf.j2 b/templates/conf/prometheus-mongodb-exporter.j2 similarity index 100% rename from templates/conf/mongodb-exporter.conf.j2 rename to templates/conf/prometheus-mongodb-exporter.j2 diff --git a/templates/conf/prometheus-postgres-exporter.j2 b/templates/conf/prometheus-postgres-exporter.j2 new file mode 100644 index 0000000..c59ce6f --- /dev/null +++ b/templates/conf/prometheus-postgres-exporter.j2 @@ -0,0 +1,2 @@ +# {{ ansible_managed }} +DATA_SOURCE_NAME="user={{ prometheus_postgres_exporter_user|default("postgres") }} host={{ prometheus_postgres_exporter_host|default("/var/run/postgresql/") }} sslmode={{ prometheus_postgres_exporter_sslmode|default("disable") }}" diff --git a/templates/systemd/prometheus-mongodb-exporter.service.j2 b/templates/systemd/prometheus-mongodb-exporter.service.j2 index 50839ca..ea78bae 100644 --- a/templates/systemd/prometheus-mongodb-exporter.service.j2 +++ b/templates/systemd/prometheus-mongodb-exporter.service.j2 @@ -5,7 +5,7 @@ After=network.target [Service] Type=simple ExecStart=/usr/local/bin/prometheus-mongodb-exporter -EnvironmentFile=/etc/mongodb-exporter.conf +EnvironmentFile=/etc/default/prometheus-mongodb-exporter [Install] WantedBy=multi-user.target diff --git a/templates/systemd/prometheus-postgres-exporter.service.j2 b/templates/systemd/prometheus-postgres-exporter.service.j2 index 53b577e..204a439 100644 --- a/templates/systemd/prometheus-postgres-exporter.service.j2 +++ b/templates/systemd/prometheus-postgres-exporter.service.j2 @@ -1,10 +1,12 @@ [Unit] Description=Prometheus PostgreSQL Exporter After=network.target - + [Service] Type=simple +User={{ prometheus_postgres_exporter_user|default("postgres") }} ExecStart=/usr/local/bin/prometheus-postgres-exporter - +EnvironmentFile=/etc/default/prometheus-postgres-exporter + [Install] WantedBy=multi-user.target