要在 prometheus 中收集 Postgres 指標,請使用 postgres_exporter。不使用容器化,一切都在本地完成。通過作業在 prometheus 中收集硬體指標。要收集資料庫指標,我需要將 prometheus_exporter 連接到資料庫。告訴我如何配置與資料庫的連接。postgres_exporter 沒有組態檔。可以通過環境變數來做到這一點嗎?
prometheus.yml:
scrape_configs:
- job_name: postgresql
static_configs:
- targets: ['xx.xx.xx.xx:9187']
labels:
alias: postgres
uj5u.com熱心網友回復:
是否可以通過環境變數來做到這一點?
對的,這是可能的。以下是支持的變數串列:https : //github.com/prometheus-community/postgres_exporter#environment-variables
如何配置與資料庫的連接
一個簡單的例子:
DATA_SOURCE_NAME="user=postgres host=database.example.com" postgres_exporter
如果您從分發包安裝匯出器,則可能有一個systemd單元檔案將其作為服務運行:
# 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/380409.html
標籤:PostgreSQL的 环境变量 普罗米修斯 格拉法纳
