1、下载postgres_exporter部署包
curl -L -O https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0/postgres_exporter-0.15.0.linux-amd64.tar.gz
2、解压并拷贝命令
temdir=$(mktemp -d)
tar xvf postgres_exporter-0.15.0.linux-amd64.tar.gz -C ${temdir}
sudo cp ${temdir}/postgres_exporter-0.15.0.linux-amd64/postgres_exporter /usr/local/bin/
3、启动postgres_exporter服务
cat <<'EOF' | sudo tee /usr/lib/systemd/system/postgres_exporter.service >> /dev/null
[Unit]
Description=postgres_exporter
Documentation=https://github.com/prometheus-community/postgres_exporter
Wants=network.service
After=network.service
[Service]
Type=simple
User=postgres
Environment=DATA_SOURCE_USER=postgres
Environment=DATA_SOURCE_PASS=123456
Environment=DATA_SOURCE_URI=localhost:5432/postgres?sslmode=disable
ExecStart=/usr/local/bin/postgres_exporter --we