To collect Postgres metrics in prometheus, postgres_exporter is used. Containerization is not used, everything is done natively. Hardware metrics are collected in a prometheus through a job. To collect database metrics, I need to connect the prometheus_exporter to the database. Tell me how to configure the connection to the database. postgres_exporter has no configuration files. Шs it possible to do this via environment variables?
prometheus.yml:
scrape_configs:
- job_name: postgresql
static_configs:
- targets: ['xx.xx.xx.xx:9187']
labels:
alias: postgres
CodePudding user response:
Is it possible to do this via environment variables?
Yes, it is possible. Here is the list of supported variables: https://github.com/prometheus-community/postgres_exporter#environment-variables
How to configure the connection to the database
A simple example:
DATA_SOURCE_NAME="user=postgres host=database.example.com" postgres_exporter
If you installed the exporter from distribution packages, there's probably a systemd
unit file to run it as a service:
# systemctl cat prometheus-postgres-exporter
# /lib/systemd/system/prometheus-postgres-exporter.service
[Unit]
Description=Prometheus PostgreSQL Exporter
Wants=network-online.target
[Service]
User=postgres
ExecStart=/usr/sbin/postgres-exporter $OPTIONS
# You can place environment variables in this file ⤋
EnvironmentFile=/etc/default/prometheus-postgres-exporter
[Install]
WantedBy=multi-user.target