ansible-debops-infrastructure

DebOps and Ansible scripts to manage my infrastructure
git clone git://git.erethon.com/ansible-debops-infrastructure
Log | Files | Refs

commit f2c2dc35d6fbdd7e529d7e1a246c882b01480cb3
parent 6cebeebe2933f131dc515f9f4f6f9139c804b568
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date:   Wed, 18 Mar 2020 00:43:47 +0200

monitoring: Setup postgres exporter on PG hosts

Diffstat:
ansible/inventory/group_vars/all/postgresql_server.yml | 11+++++++++++
ansible/roles/monitoring/handlers/main.yml | 12++++++++++++
ansible/roles/monitoring/tasks/main.yml | 24+++++++++++++++++++++++-
ansible/roles/monitoring/templates/sysconfig.postgres_exporter.j2 | 2++
4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/ansible/inventory/group_vars/all/postgresql_server.yml b/ansible/inventory/group_vars/all/postgresql_server.yml @@ -5,3 +5,14 @@ postgresql_server__autopostgresqlbackup: False postgresql_server__auto_backup: False postgresql_server__packages: ['prometheus-postgres-exporter'] + +ferm__group_rules: + - name: 'postgres_exporter' + type: 'accept' + filename: 'postgres_exporter' + table: 'filter' + chain: 'INPUT' + dport: [ 9187 ] + saddr: "{% if hostvars['prometheus_host'] is defined %} {{ hostvars['prometheus_host'].ansible_host }} {% else %} '127.0.0.1' {% endif %}" + protocol: 'tcp' + domain: 'ip' diff --git a/ansible/roles/monitoring/handlers/main.yml b/ansible/roles/monitoring/handlers/main.yml @@ -0,0 +1,12 @@ +--- + +- name: Restart node exporter + systemd: + name: prometheus-postgres-exporter + state: restarted + +- name: Restart postgres exporter + systemd: + name: prometheus-postgres-exporter + state: restarted + daemon_reload: yes diff --git a/ansible/roles/monitoring/tasks/main.yml b/ansible/roles/monitoring/tasks/main.yml @@ -1,9 +1,31 @@ --- -- name: Copy systemd environment file +- name: Copy systemd node exporter environment file template: src: sysconfig.node_exporter.j2 dest: /etc/default/prometheus-node-exporter owner: root group: root mode: 0644 + notify: + - Restart node exporter + +- name: Copy systemd postgres exporter environment file + template: + src: sysconfig.postgres_exporter.j2 + dest: /etc/default/prometheus-postgres-exporter + owner: root + group: root + mode: 0644 + when: inventory_hostname in groups.debops_service_postgresql_server + notify: + - Restart postgres exporter + +- name: Run postgres exporter as the postgres user + lineinfile: + path: /etc/systemd/system/multi-user.target.wants/prometheus-postgres-exporter.service + regexp: '^User= ' + line: User=postgres + when: inventory_hostname in groups.debops_service_postgresql_server + notify: + - Restart postgres exporter diff --git a/ansible/roles/monitoring/templates/sysconfig.postgres_exporter.j2 b/ansible/roles/monitoring/templates/sysconfig.postgres_exporter.j2 @@ -0,0 +1,2 @@ +DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/" +ARGS="--web.listen-address={{ node_exporter__listen_address }}:9187"