feat(postgres_exporter): add ansible role for deployment using docker

This commit is contained in:
transcaffeine 2022-03-13 08:41:06 +01:00
parent a911b83616
commit fc65595bce
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
4 changed files with 82 additions and 0 deletions

View File

@ -11,6 +11,9 @@ metrics or alerting.
manager receiver which posts alerts to a configured matrix channel manager receiver which posts alerts to a configured matrix channel
using alertmanagers' webhooks. using alertmanagers' webhooks.
- [`postgres_exporter`](roles/postgres_exporter/README.md): Prometheus
exporter for postgres databases, in a docker container.
## License ## License
[CNPLv7+](LICENSE.md): Cooperative Nonviolent Public License [CNPLv7+](LICENSE.md): Cooperative Nonviolent Public License

View File

@ -0,0 +1,18 @@
# `finallycoffee.observability.postgres_exporter` ansible role
## Overview
Ansible role to deploy [`postgres_exporter`](https://github.com/prometheus-community/postgres_exporter),
running in a docker container.
## Configuration
Set `postgres_exporter_db_[host|post|user|pass]` according to your
databases configuration, and scrape the container on it's port `9187`
(e.g.: `http://{container_ip}:9187/metrics`).
For more configuration options using environment variables, see the
[official README](https://github.com/prometheus-community/postgres_exporter)
and set the configuration in `postgres_exporter_container_env` to override
the defaults.

View File

@ -0,0 +1,31 @@
---
postgres_exporter_version: "0.10.1"
postgres_exporter_user: root
postgres_exporter_create_user: false
postgres_exporter_db_host: ~
postgres_exporter_db_user: postgres
postgres_exporter_db_pass: ~
postgres_exporter_db_port: ~
postgres_exporter_db_sslmode: false
postgres_exporter_container_name: postgres_exporter
postgres_exporter_container_image_name: quay.io/prometheuscommunity/postgres-exporter
postgres_exporter_container_image_tag: ~
postgres_exporter_container_image_ref: "{{ postgres_exporter_container_image_name }}:{{ postgres_exporter_container_image_tag | default('v' + postgres_exporter_version, True) }}"
postgres_exporter_container_networks: ~
postgres_exporter_container_purge_networks: false
postgres_exporter_container_volumes: []
postgres_exporter_container_ports: ~
postgres_exporter_container_env:
DATA_SOURCE_NAME: >-
user={{ postgres_exporter_db_user }}
host={{ postgres_exporter_db_host }}
sslmode={{ 'enable' if postgres_exporter_db_sslmode else 'disable' }}
{%- if postgres_exporter_db_pass -%} pass={{ postgres_exporter_db_pass }}{% endif -%}
{%- if postgres_exporter_db_port -%} port={{ postgres_exporter_db_port }}{% endif -%}
postgres_exporter_container_labels:
VERSION: "{{ postgres_exporter_version }}"
postgres_exporter_container_user: "{{ postgres_exporter_user if not postgres_exporter_create_user else postgres_exporter_user_info.uid }}"
postgres_exporter_container_restart_policy: unless-stopped

View File

@ -0,0 +1,30 @@
---
- name: Ensure user '{{ postgres_exporter_user }}' exists
user:
name: "{{ postgres_exporter_user }}"
state: present
system: yes
register: postgres_exporter_user_info
when: postgres_exporter_create_user
- name: Ensure container image '{{ postgres_exporter_container_image_ref }}' is available
community.docker.docker_image:
name: "{{ postgres_exporter_container_image_ref }}"
state: present
source: pull
force_source: "{{ 'yes' if postgres_exporter_container_image_tag else 'no' }}"
- name: Ensure postgres exporter container '{{ postgres_exporter_container_name }}' is running
docker_container:
name: "{{ postgres_exporter_container_name }}"
image: "{{ postgres_exporter_container_image_ref }}"
networks: "{{ postgres_exporter_container_networks | default(omit) }}"
purge_networks: "{{ postgres_exporter_container_purge_networks }}"
volumes: "{{ postgres_exporter_container_volumes | default(omit) }}"
labels: "{{ postgres_exporter_container_labels | default(omit) }}"
ports: "{{ postgres_exporter_container_ports | default(omit) }}"
user: "{{ postgres_exporter_container_user }}"
env: "{{ postgres_exporter_container_env }}"
restart_policy: "{{ postgres_exporter_container_restart_policy }}"
state: started