Greenplum數倉監控解決方案(開源版本)


Greenplum監控解決方案

基於Prometheus+Grafana+greenplum_exporter+node_exporter實現

關聯圖

一、基本概念

1.Prometheus

​ Prometheus時序數據庫:存儲的是時序數據,即按相同時序(相同名稱和標簽),以時間維度存儲連續的數據的集合,lPrometheus Server, 負責從 Exporter 拉取和存儲監控數據,並提供一套靈活的查詢語言(PromQL)供用戶使用。

lExporter, 負責收集目標對象(host, container…)的性能數據,並通過 HTTP 接口供 Prometheus Server 獲取。

l可視化組件,監控數據的可視化展現對於監控方案至關重要。以前 Prometheus 自己開發了一套工具,不過后來廢棄了,因為開源社區出現了更為優秀的產品 Grafana。Grafana 能夠與 Prometheus 無縫集成,提供完美的數據展示能力。

lAlertmanager,用戶可以定義基於監控數據的告警規則,規則會觸發告警。一旦 Alermanager 收到告警,會通過預定義的方式發出告警通知。支持的方式包括 Email、PagerDuty、Webhook 等。

2. Grafana 介紹

Grafana是一個跨平台的開源的度量分析和可視化工具,可以通過將采集的數據查詢然后可視化的展示,並及時通知。

1、展示方式:快速靈活的客戶端圖表,面板插件有許多不同方式的可視化指標和日志,官方庫中具有豐富的儀表盤插件,比如熱圖、折線圖、圖表等多種展示方式;

2、支持數據源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;

3、通知提醒:以可視方式定義最重要指標的警報規則,Grafana將不斷計算並發送通知,在數據達到閾值時通過Slack、PagerDuty等獲得通知;

4、混合展示:在同一圖表中混合使用不同的數據源,可以基於每個查詢指定數據源,甚至自定義數據源;

5、注釋:使用來自不同數據源的豐富事件注釋圖表,將鼠標懸停在事件上會顯示完整的事件元數據和標記;

6、過濾器:Ad-hoc過濾器允許動態創建新的鍵/值過濾器,這些過濾器會自動應用於使用該數據源的所有查詢。

二、Greenplum監控的實現

2.1Prometheus安裝

源碼編譯安裝(推薦官網

2.1.1下載源碼包文件

$ cd usr/local/src/tools/    #自定義文件下載目錄

命令下載(服務器可訪問外網狀態)

$ wget https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gz   

注:下載到本地通過第三方工具上載到服務器指定位置(服務器不可訪問外網)

解壓文件到自定義目錄

tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local/
mv prometheus-2.27.1.linux-amd64/ prometheus     #修改文件名便於管理
cd /usr/local/prometheus/

解壓后文件目錄

2.1.2創建用戶用於管理啟動prometheus服務

$ groupadd prometheus
$ useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
$ chown prometheus.prometheus -R /usr/local/prometheus

2.1.3啟動prometheus

注:啟動方式有以下兩種建議選擇第二種執行方式便於管理服務

1.直接執行prometheus命令
cd /usr/local/prometheus
nohup ./prometheus & 
ps -ef | grep prometheus      #檢查后台進程

2.配置系統systemd服務

(注:如啟動失敗查看當前系統服務啟動日志cat /var/log/messages 如已按上述命令啟動需kill掉當前后台運行進程才能重新運行下列啟動命令)

cat > /usr/lib/systemd/system/prometheus.service <<EOF
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple                     #默認
User=prometheus					#管理啟動用戶
ExecStart=/usr/local/prometheus/prometheus -- config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

啟動prometheus服務

systemctl daemon-reload        #重新加載服務配置文件
systemctl start prometheus.service
systemctl status prometheus.service
systemctl enable prometheus.service

3.前端驗證

啟動后進行前端驗證 訪問成功效果顯示如下(注:如訪問不成功檢查端口開放情況及防火牆狀態)

http://192.128.xxx.xxx:9090 (IP:端口)

2.2配置安裝node_exporter

node_exporter的作用是用於機器系統數據收集,監控服務器CPU、內存、磁盤、I/O等信息。安裝在需要監控的服務器上

測試安裝服務器:(注意:node_exporter 的運行用戶也是 prometheus 用戶需要在每台節點上都創建該用戶。)

192.168.xxx.xxx

192.168.xxx.xxx

192.168.xxx.xxx

192.168.xxx.xxx

2.2.1下載安裝

cd /usr/local/src/tools/       #該目錄為自定義存放源碼包目錄
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
mv node_exporter-1.0.1.linux-amd64/ node_exporter

2.2.2創建用戶(如果已創建可以忽略)

groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
chown prometheus.prometheus -R /usr/local/node_exporter

2.2.3啟動node_exporter

注:啟動方式有以下兩種建議選擇第二種執行方式便於管理服務

1.直接執行node_exporter命令
cd /usr/local/node_exporter

nohup ./node_exporter &

ps -ef|grep node_exporter     #查看后台進程狀態
2.配置系統systemd服務(注:如已按上述命令啟動需kill 掉當前后台運行進程 才能運行命令重啟下列服務)
cat > /usr/lib/systemd/system/node_exporter.service <<EOF
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple                     
User=prometheus				
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

啟動node_exporter

systemctl daemon-reload
systemctl start node_exporter.service
systemctl enable node_exporter.service
systemctl status node_exporter.service

3.前端驗證

http://192.168.xxx.xxx:9100/metrics、http://192.168.xxx.xxx:9100/metrics..........................

2.3Grafana安裝

1.下載、安裝

官網地址 https://grafana.com/grafana/download

找到對應系統版本運行如下命令:

源碼包下載(可選)

wget https://dl.grafana.com/oss/release/grafana-7.5.7.linux-amd64.tar.gz
tar -zxvf grafana-7.5.7.linux-amd64.tar.gz

解壓文件后文件目錄

rpm 包下載(可選)

wget https://dl.grafana.com/oss/release/grafana-7.5.7-1.x86_64.rpm 
sudo yum install grafana-7.5.7-1.x86_64.rpm 
配置文件位於/etc/grafana/grafana.ini,這里暫時保持默認配置即可
2.啟動 Grafana
systemctl enable grafana-server.service
systemctl start grafana-server.service
systemctl status grafana-server.service

3.前端驗證及配置添加

http://192.168.xxx.xxx:3000

默認登錄用戶admin 密碼 admin然后下一步會提示修改新的密碼。重新登錄后如下圖,表示配置成功

登錄進去后會提示修改密碼>>>>>>>>點擊添加數據庫>>>>>>>選擇添加prometheus數據庫>>>>>點擊Doshboards>>>>>選擇添加Promethus 2.0 >>>>>>完善URL路徑信息后選擇添加>>>>>>切換點擊Doshboards




2.4greenplum_exporter安裝

1.檢查安裝go語言編譯器(前提)

cd /usr/local/src/tools/    #自定義源碼文件包目錄
wget https://gomirrors.org/dl/go/go1.14.12.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.14.12.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go env -w GO111MODULE=on                     #修改go環境變量
go env -w GOPROXY=https://goproxy.io,direct  
go env 	#查看當前go環境變量

注:完成安裝go語言后可能會出現以下錯誤(錯誤原因 在64系統里執行32位程序)

解決辦法:

yum install glibc.i686      

注:如有相關版本go語言環境,查找到當前go語言安裝路徑位置設置到環境變量中

go version            #查看當前系統版本
find / -name golang*    #查找當前按系統環境配置
vi /etc/profile	

2.編譯greenplum_exporter

git clone https://github.com/tangyibo/greenplum_exporter  
cd greenplum_exporter/ && make build
cd bin && ls -l
注:正常解壓完后bin目錄下會有greenplum_exporter啟動程序

3.啟動采集器greenplum_exporter

export GPDB_DATA_SOURCE_URL=postgres://gpadmin:123456@192.168.xxx.xxx:5432/postgres?sslmode=disable

nohup ./greenplum_exporter --web.listen-address="192.168.xxx.xxx:9297" --web.telemetry-path="/metrics" --log.level=error &   #啟動命令

注:環境變量GPDB_DATA_SOURCE_URL指定了連接Greenplum數據庫的連接串(請使用gpadmin賬號連接postgres庫),該連接串以postgres://為前綴,具體格式如下:
postgres://gpadmin:password@192.168.xxx.xxx:5432/postgres?sslmode=disable
postgres://[數據庫連接賬號,必須為gpadmin]:[賬號密碼,即gpadmin的密碼]@[數據庫的IP地址]:[數據庫端口號]/[數據庫名稱,必須為postgres]?[參數名]=[參數值]&[參數名]=[參數值]

也可配置編寫腳本文件添加為開機自啟

4.前端驗證

訪問greenplum_exporter的web界面http://192.168.xxx.xxx:9297/metrics (GP數倉啟動才能采集到數據)

三、在Prometheus中配置Greenplum Exporter

prometheus的服務端通過pull向各個node_exporter節點端抓取信息,需要在各個node上安裝exporter。可以利用 Prometheus 的 static_configs 來拉取 node_exporter 的數據。

1.編輯prometheus.yml文件

編輯一下文件,主要修改scrape_configs模塊即可
vim /usr/local/prometheus/prometheus/prometheus.yml
添加內容
 - job_name: 'gp-sdw1'
    static_configs:
    - targets: ['192.168.xxx.xxx:9100']
  - job_name: 'gpeenplum'
    static_configs:
    - targets: ['192.168.xxx.xxx:9297']
  - job_name: 'gp-mdw'
    static_configs:
    - targets: ['192.168.xxx.xxx:9100']
  - job_name: 'gp-sdw2'
    static_configs:
    - targets: ['192.168.xxx.xxx:9100']
  - job_name: 'gp-sdw3-mdw2'
    static_configs:
    - targets: ['192.168.xxx.xxx:9100']

2.添加完成后重啟prometheus服務

ps -ef|grep prometheus
kill -9 當前進程
systemctl start prometheus.service

前端驗證http://192.168.xxx.xxx:9090/targets

四、導入JSON 文件是實現greenplum_exporter、node_exporter監控指標

1.下載JSON 文件(示例控制台)

greenplum_exporter的JSON文件下載地址: https://grafana.com/grafana/dashboards/13822

node_exporter的JSON文件下載地址: https://grafana.com/grafana/dashboards/8919

把文件導入到grafana中:Manage -- > Import --> Import via panel json(填入下載的JSON文件)
以下是導入文件后的效果,主要了解導入操作步驟,前端頁面配置細節較多,有興趣的同學也可搜索相關文章了解



能力有限,希望能給各位同學帶來一定的幫助


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM