diff --git a/defaults/main.yml b/defaults/main.yml index 3b33404..a11aa6d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -17,6 +17,9 @@ prometheus_phpfpm_sockets_directory: "/run/php/" prometheus_postgres_exporter_host: "/var/run/postgresql/" prometheus_postgres_exporter_sslmode: "disable" prometheus_postgres_exporter_user: "postgres" +prometheus_postgres_exporter_password: "changeme_" +prometheus_postgres_exporter_port: 5432 + prometheus_retention_time: "15d" diff --git a/templates/conf/prometheus-postgres-exporter.j2 b/templates/conf/prometheus-postgres-exporter.j2 index e7f1355..6c3e358 100644 --- a/templates/conf/prometheus-postgres-exporter.j2 +++ b/templates/conf/prometheus-postgres-exporter.j2 @@ -1,2 +1,6 @@ # {{ ansible_managed }} +{% if (prometheus_postgres_exporter_user is defined) and (prometheus_postgres_exporter_password is defined) %} +DATA_SOURCE_NAME=postgresql://{{ prometheus_postgres_exporter_user }}:{{ prometheus_postgres_exporter_password }}@{{ prometheus_postgres_exporter_host }}:{{ prometheus_postgres_exporter_port }}/postgres?sslmode=prometheus_postgres_exporter_sslmode +{% else %} DATA_SOURCE_NAME="user={{ prometheus_postgres_exporter_user }} host={{ prometheus_postgres_exporter_host }} sslmode={{ prometheus_postgres_exporter_sslmode }}" +{% endif %} diff --git a/templates/conf/prometheus.yml.j2 b/templates/conf/prometheus.yml.j2 index 187b3e7..8ccf28d 100644 --- a/templates/conf/prometheus.yml.j2 +++ b/templates/conf/prometheus.yml.j2 @@ -91,11 +91,22 @@ scrape_configs: scrape_interval: 30s scrape_timeout: 10s static_configs: +{% if prometheus_postgres_exporter_custom is defined %} +{% for target in prometheus_postgres_exporter_custom.values() %} + - targets: ['{{ target.node_name }}:9187'] + labels: + environment: '{{ target.environment }}' + node_name: '{{ target.node_name }}' + service_name: '{{ target.service_name }}' + cluster: '{{ target.cluster }}' +{% endfor %} +{% else %} - targets: {% for target in prometheus_postgres_exporter_targets %} - {{ target }}:9187 {% endfor %} {% endif %} +{% endif %} {% if prometheus_phpfpm_exporter_targets is defined %} - job_name: phpfpm