Add Postgres monitoring for Prometheus

This commit is contained in:
Thomas Kleinendorst 2024-10-21 09:43:27 +02:00
parent 653aef8c38
commit 4054f1a02e
4 changed files with 27 additions and 0 deletions

View file

@ -11,6 +11,9 @@ prometheus_targets:
grafana: grafana:
- targets: - targets:
- raspberry-pi-1.kleinendorst.info:3000 - raspberry-pi-1.kleinendorst.info:3000
postgres:
- targets:
- raspberry-pi-1.kleinendorst.info:9187
prometheus_web_listen_address: 127.0.0.1:9090 prometheus_web_listen_address: 127.0.0.1:9090
prometheus_scrape_configs: prometheus_scrape_configs:
- job_name: "prometheus" - job_name: "prometheus"
@ -25,6 +28,10 @@ prometheus_scrape_configs:
file_sd_configs: file_sd_configs:
- files: - files:
- "{{ prometheus_config_dir }}/file_sd/grafana.yml" - "{{ prometheus_config_dir }}/file_sd/grafana.yml"
- job_name: "postgres"
file_sd_configs:
- files:
- "{{ prometheus_config_dir }}/file_sd/postgres.yml"
prometheus_alertmanager_config: prometheus_alertmanager_config:
- static_configs: - static_configs:
- targets: - targets:

View file

@ -13,6 +13,9 @@
- name: Register current user in a variable - name: Register current user in a variable
ansible.builtin.set_fact: ansible.builtin.set_fact:
container_user: "{{ whoami.stdout }}" container_user: "{{ whoami.stdout }}"
- name: Set default podman_simple_container_volumes if not provided
ansible.builtin.set_fact:
podman_simple_container_volumes: "{{ podman_simple_container_volumes | default([]) }}"
- name: Create mount directories - name: Create mount directories
ansible.builtin.file: ansible.builtin.file:
path: "/home/{{ container_user }}/{{ item.name }}" path: "/home/{{ container_user }}/{{ item.name }}"

View file

@ -51,3 +51,19 @@
- ssl_key_file=/var/lib/postgresql/privkey.pem - ssl_key_file=/var/lib/postgresql/privkey.pem
podman_container_env: podman_container_env:
POSTGRES_PASSWORD: "{{ postgres_password }}" POSTGRES_PASSWORD: "{{ postgres_password }}"
- name: Create the postgres prometheus exporter container
ansible.builtin.include_role:
name: podman-container
apply:
become: true
become_user: "{{ postgres_unix_username }}"
vars:
podman_container_name: postgres-prometheus-exporter
podman_container_image: quay.io/prometheuscommunity/postgres-exporter
podman_container_tag: "{{ postgres_prometheus_exporter_version }}"
podman_container_publish:
- 0.0.0.0:9187:9187
podman_container_env:
DATA_SOURCE_URI: "postgres.kleinendorst.info:5432/postgres"
DATA_SOURCE_USER: "postgres"
DATA_SOURCE_PASS: "{{ postgres_password }}"

View file

@ -1,3 +1,4 @@
--- ---
postgres_unix_username: postgres postgres_unix_username: postgres
postgres_version: 17-alpine postgres_version: 17-alpine
postgres_prometheus_exporter_version: v0.15.0