PG的Prometheus監控

  • 2019 年 10 月 4 日
  • 筆記

到github上,下載已編譯好的exporter文件

地址: https://github.com/wrouesnel/postgres_exporter/releases

tar xf postgres_exporter_v0.4.1_linux-amd64.tar.gz -C /opt/

cd /opt/postgres_exporter_v0.4.1_linux-amd64

vim start.sh 啟動腳本內容如下

#!/bin/bash    cd /opt/postgres_exporter_v0.4.1_linux-amd64  export PATH=/usr/local/pgsql/bin:$PATH    # 下面的password替換為你自己的postgres用戶的密碼  export  DATA_SOURCE_NAME="user=postgres host=localhost password=123456 port=5432 dbname=postgres sslmode=disable"    nohup ./postgres_exporter --web.listen-address=":9187" >/dev/null 2>&1 &

然後,到Prometheus裡面去加上對應的target

採集到數據後,就可以在 grafana裡面畫圖了,類似這樣:

通常,我們還會同時部署個node_exporter 採集下主機級別的監控資訊。類似這樣:

因為blog不方便上傳文件,這裡我就不貼 grafana模板文件了。