metrics: add postgres-exporter and pg-agent

* postgres-exporter for basic database metrics
  - pg-agent: optional, to identify query performence issues

Signed-off-by: Alexis Pentori <alexis@status.im>
This commit is contained in:
Alexis Pentori 2024-10-09 10:46:21 +02:00
parent fbc3376e79
commit e48e129d8b
No known key found for this signature in database
GPG Key ID: 65250D2801E47A10
5 changed files with 65 additions and 0 deletions

View File

@ -67,6 +67,11 @@ Container share memory can be configured with:
postgres_share_memory: '1g' postgres_share_memory: '1g'
``` ```
Metrics exporter for query performance can be activated with:
```yaml
postgres_ha_perf_metrics_exporter_disabled: false
```
# Management # Management
The service is managed using [Docker Compose](https://docs.docker.com/compose/): The service is managed using [Docker Compose](https://docs.docker.com/compose/):
@ -75,4 +80,5 @@ admin@node-01.example.org:/docker/postgres-ha % docker-compose ps
Name Command State Ports Name Command State Ports
-------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------
postgres-ha docker-entrypoint.sh -p 5433 Up (healthy) 5432/tcp, 0.0.0.0:5433->5433/tcp postgres-ha docker-entrypoint.sh -p 5433 Up (healthy) 5432/tcp, 0.0.0.0:5433->5433/tcp
pg-metrics-exporter /bin/postgres_exporter Up 0.0.0.0:9187->9187/tcp
``` ```

View File

@ -51,6 +51,18 @@ postgres_ha_users: []
# - user: 'dbuser' # - user: 'dbuser'
# pass: 'dbpass' # pass: 'dbpass'
# Metrics Exporter
postgres_ha_metrics_exporter_cont_name: 'pg-metrics-exporter'
postgres_ha_metrics_exporter_cont_version: 'v0.15.0'
postgres_ha_metrics_exporter_cont_image: 'quay.io/prometheuscommunity/postgres-exporter:{{ postgres_ha_metrics_exporter_cont_version}}'
postgres_ha_metrics_exporter_cont_port: 9187
# Performence Metrics Exporter
postgres_ha_perf_metrics_exporter_disabled: true
postgres_ha_perf_metrics_exporter_cont_name: 'pg-perf-metrics-exporter'
postgres_ha_perf_metrics_exporter_cont_version: '1.2.6'
postgres_ha_perf_metrics_exporter_cont_image: 'ghcr.io/coroot/coroot-pg-agent:{{ postgres_ha_perf_metrics_exporter_cont_version }}'
postgres_ha_perf_metrics_exporter_cont_port: 9188
# Backups # Backups
postgres_ha_backup: true postgres_ha_backup: true
postgres_ha_backup_enabled: true postgres_ha_backup_enabled: true

View File

@ -24,3 +24,25 @@
name: 'PostgreSQL {{ postgres_ha_replica_enabled | ternary("Replica", "Tables") }} Healthcheck' name: 'PostgreSQL {{ postgres_ha_replica_enabled | ternary("Replica", "Tables") }} Healthcheck'
type: 'script' type: 'script'
script: '{{ postgres_ha_service_path }}/health.sh' script: '{{ postgres_ha_service_path }}/health.sh'
- name: 'postgres-metrics'
id: '{{ postgres_ha_metrics_exporter_cont_name }}'
tags: [ 'postgres-metrics', 'perf']
port: '{{ postgres_ha_metrics_exporter_cont_port }}'
address: '{{ ansible_local.wireguard.address }}'
checks:
- id: '{{ postgres_ha_metrics_exporter_cont_name }}-status'
name: 'PostgreSQL Metrics exporter'
type: 'tcp'
tcp: 'localhost:{{ postgres_ha_metrics_exporter_cont_port }}'
- name: 'postgres-perf-metrics'
id: '{{ postgres_ha_perf_metrics_exporter_cont_name }}'
tags: [ 'postgres-metrics', 'perf']
port: '{{ postgres_ha_perf_metrics_exporter_cont_port }}'
address: '{{ ansible_local.wireguard.address }}'
disabled: '{{ postgres_ha_perf_metrics_exporter_disabled | to_json }}'
checks:
- id: '{{ postgres_ha_perf_metrics_exporter_cont_name }}-status'
name: 'PostgreSQL Metrics exporter'
type: 'tcp'
tcp: 'localhost:{{ postgres_ha_perf_metrics_exporter_cont_port }}'

View File

@ -40,6 +40,27 @@ services:
'-U', '{{ postgres_ha_admin_user }}' '-U', '{{ postgres_ha_admin_user }}'
] ]
metrics-exporter:
image: '{{ postgres_ha_metrics_exporter_cont_image }}'
container_name: '{{ postgres_ha_metrics_exporter_cont_name }}'
environment:
DATA_SOURCE_URI: '{{ postgres_ha_cont_name }}:{{ postgres_ha_cont_port }}/{{ postgres_ha_db_name }}?sslmode=disable'
DATA_SOURCE_USER: '{{ postgres_ha_admin_user }}'
DATA_SOURCE_PASS: '{{ postgres_ha_admin_pass }}'
ports:
- '{{ postgres_ha_metrics_exporter_cont_port }}:{{ postgres_ha_metrics_exporter_cont_port }}'
{% if not postgres_ha_perf_metrics_exporter_disabled %}
perf-metrics-exporter:
image: '{{ postgres_ha_perf_metrics_exporter_cont_image }}'
container_name: '{{ postgres_ha_perf_metrics_exporter_cont_name }}'
environment:
DSN:"postgresql://{{ postgres_ha_cont_name }}:{{ postgres_ha_cont_port }}@{{ postgres_ha_cont_name }}:{{postgres_ha_cont_port }}/{{ postgres_ha_db_name }}?connect_timeout=1&statement_timeout=30000&sslmode=disable"
LISTEN:"0.0.0.0:{{ postgres_ha_perf_metrics_exporter_cont_port }}"
ports:
- '{{ postgres_ha_perf_metrics_exporter_cont_port }}:{{ postgres_ha_perf_metrics_exporter_cont_port }}'
{% endif %}
{% if postgres_ha_cont_networks != [] %} {% if postgres_ha_cont_networks != [] %}
networks: networks:
{% for network in postgres_ha_cont_networks %} {% for network in postgres_ha_cont_networks %}

View File

@ -2,3 +2,7 @@
{% for key,val in postgres_ha_alter_system_settings.items() %} {% for key,val in postgres_ha_alter_system_settings.items() %}
ALTER SYSTEM SET {{ key }} = '{{ val }}'; ALTER SYSTEM SET {{ key }} = '{{ val }}';
{% endfor %} {% endfor %}
{% if not postgres_ha_perf_metrics_exporter_disabled %}
CREATE extension pg_stat_statements;
ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_statements';
{% endif %}