PostgreSQL監控之pgwatch2

來源:互聯網
上載者:User

標籤:下一步   enable   英文   模式   proc   lib   state   git clone   安裝過程   

前言:
  • 雖然作者已經推出了docker版本,只需一鍵(一條命令)即可完成搭建。
  • 但是本著學習的心理還是要自己折騰一遍,一鍵雖好但不明了啊。
  • 官方已經把安裝寫的很詳細了,但畢竟是英文......
  • pgwatch2官方地址:https://github.com/cybertec-postgresql/pgwatch2
系統內容:
CentOS 7.5IP:192.168.1.2grafana-5.1.4PostgreSQL-10、pg_stat_statements模組InfluxDB-1.5.3Python3#關閉selinux以及firewalld。##自行安裝以上應用!!!本文不提供安裝過程!!!
一、配置PostgreSQL
vi /var/lib/pgsql/10/data/postgresql.confshared_preload_libraries = ‘pg_stat_statements‘track_io_timing = on#編輯postgresql.conf設定檔,添加如下兩行(前提:裝好pg_stat_statements模組vi  /var/lib/pgsql/10/data/pg_hba.conflocal   all             all                                     peerhost    all             all             127.0.0.1/32            trusthost    all             all             ::1/128                 trust#修改認證模式,通過127.0.0.1訪問的使用者不要求輸入密碼認證#為了安全請自行配置,pg_hba.conf設定檔詳解請自行百度~~


systemctl restart postgresql-10.service#重啟資料庫mkdir /app && cd /appgit clone https://github.com/cybertec-postgresql/pgwatch2.git#複製源碼倉庫,有一些東西需要用到。

su - postgrespsql -c "create user pgwatch2_grafana password ‘xyz‘"psql -c "create database pgwatch2_grafana owner pgwatch2_grafana"psql -c "create user pgwatch2 password ‘xyz‘"psql -c "create database pgwatch2 owner pgwatch2"psql -f /app/pgwatch2/pgwatch2/sql/datastore_setup/config_store.sql pgwatch2psql -f /app/pgwatch2/pgwatch2/sql/datastore_setup/metric_definitions.sql pgwatch2#切換至postgre使用者以便操作資料庫。#建立pgwatch2_grafana、pgwatch2使用者並設定密碼。#建立pgwatch2_grafana、pgwatch2資料庫並設定所屬主。#匯入pgwatch2的資料。
二、配置InfluxDB
vi /etc/influxdb/influxdb.conf[http]enabled = truebind-address = "127.0.0.1:8086"#修改設定檔,將http端的bind-address修改成127.0.0.1#因為是做監控用的,所以不做認證,但僅允許本地地址訪問。systemctl start influxdb#啟動InfluxDB

influxCREATE USER "pgwatch2" WITH PASSWORD ‘xyz‘CREATE DATABASE pgwatch2use pgwatch2GRANT ALL ON pgwatch2 to "pgwatch2"#建立pgwatch2使用者以及同名的資料庫,並且授權。

三、配置Grafana
vi /etc/grafana/grafana.ini[database]type = postgreshost = 127.0.0.1:5432name = pgwatch2_grafanauser = pgwatch2_grafanapassword = xyz#將Grafana的資料存入postgresqlhttp://192.168.1.2:3000#訪問Grafana的web頁面進行配置#預設使用者名與密碼:admin





#開始配置儀錶盤#源碼倉庫中:pgwatch2/grafana_dashboards/v5/路徑下就是所有的儀錶盤內容,每個檔案夾為一個儀錶盤#每個檔案夾內都含有dashboard.json檔案,把這個檔案匯入即可#這裡為了展示效果我就只匯入一個:db-overview/dashboard.json#github網頁上的會比較好複製,複製網頁中的所有內容:#https://raw.githubusercontent.com/cybertec-postgresql/pgwatch2/master/grafana_dashboards/v5/db-overview/dashboard.json






四、配置pgwatch2
cd /app/pgwatch2/pip3 install -U -r webpy/requirements.txtcd webpypython3 web.py#進入pgwatch目錄,pip安裝一些依賴庫#執行web.py


#訪問web頁面進行下一步配置#配置被監控資料庫的資訊,注意,這裡填的是被監控資料庫的資訊!!!#也就是你要在對應的資料庫建立使用者並且授權,然後啟用pg_stat_statements模組#我這裡僅僅只監控本機上的pgwatch2資料庫。


#配置被監控的資料庫#這裡我就只監控pgwatch2資料庫su - postgrespsql -d pgwatch2 -c "CREATE EXTENSION pg_stat_statements;"psql -d pgwatch2 -c "CREATE EXTENSION plpythonu;"psql -f /app/pgwatch2/pgwatch2/sql/metric_fetching_helpers/stat_activity_wrapper.sql pgwatch2psql -f /app/pgwatch2/pgwatch2/sql/metric_fetching_helpers/stat_statements_wrapper.sql pgwatch2psql -f /app/pgwatch2/pgwatch2/sql/metric_fetching_helpers/cpu_load_plpythonu.sql pgwatch2psql -f /app/pgwatch2/pgwatch2/sql/metric_fetching_helpers/table_bloat_approx.sql pgwatch2#官方說明:https://github.com/cybertec-postgresql/pgwatch2#steps-to-configure-your-database-for-monitoring

#編譯pgwatch2程式yum install go -ycd /app/pgwatch2/pgwatch2./build_gatherer.sh#安裝go語言環境,進入pgwatch2目錄,執行build_gatherer.sh開始編譯#這個過程會比較慢,因為會到github上下載東西,一定要保證電腦可以ping通github#編譯完成後會產生一個pgwatch2的可執行檔

./pgwatch2#運行pgwatch2程式#因為剛才設定的所有賬戶密碼跟pgwatch2程式預設值是一致的,所有直接運行即可#若不一致,請自行使用./pgwatch2 --help查看協助#執行不報錯,接下來去Grafana看資料就行了!!!



#最後,把pgwatch2配置成可以用systemctl方式啟動#把下面的內容粘貼到/etc/systemd/system/pgwatch2.service#然後就可以用systemctl start 啟動啦#注意,通過這個方式啟動,所有的輸出資訊都會在/var/log/messages[Unit]Description=pgwatch2After=syslog.targetAfter=network.target[Service]User=rootRestart=on-failurePIDFile=/tmp/pgwatch2.pidKillMode=control-groupExecStart=/app/pgwatch2/pgwatch2/pgwatch2ExecStop=/bin/kill -SIGTERM $MAINPIDRestartSec=10sTimeoutSec=0[Install]WantedBy=multi-user.target

PostgreSQL監控之pgwatch2

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.