Flink實戰(七十):監控(二)搭建flink視覺化監控 Pushgateway+ Prometheus + Grafana (windows )
1Flink 的配置:
在flink配置⽂件flink-conf.yaml中新增:
metrics.reporter.promgateway.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter metrics.reporter.promgateway.host: localhost # promgateway 主要是Pushgateway所在機器的ip地址 metrics.reporter.promgateway.port: 9091 metrics.reporter.promgateway.jobName: zhisheng // 隨意起名 metrics.reporter.promgateway.randomJobNameSuffix:true metrics.reporter.promgateway.deleteOnShutdown: false
將flink包中opt檔案下的flink-metrics-prometheus-xxxxx.jar包複製到lib資料夾中
2 pushgateway配置
2.1 下載prometheus到window上
Prometheus 的下載連結為:
https://prometheus.io/download/
下載pushgateway-1.3.0.windows-amd64.tar.gz後解壓
3 Prometheus配置
3.1 下載prometheus到window上
Prometheus 的下載連結為:
下載prometheus-2.22.0.windows-amd64.tar.gz 後解壓
這裡所需Prometheus的元件為:
- prometheus
- pushgateway(Flink推送監控資料到此)
將這些元件分別解壓到任意目錄。
3.2 配置Prometheus
修改Prometheus根目錄prometheus.yml
檔案的scrape_config,如下圖所示:
# my global config global: scrape_interval: 15s # Set the scrape interval to every15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' honor_labels: true # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9091'] labels: instance: pushgateway
因為prometheus配置pushgateway 的時候,也會指定job和instance,但是它只表示 pushgateway例項,不能真正表達收集資料的含義。所以配置pushgateway需要新增 honor_labels:true,避免收集資料本身的job和instance被覆蓋。
4Grafana 配置
4.1 下載並啟動Grafana
下載Grafana解壓,新增prometheus資料來源。
Grafana的下載地址為: https://grafana.com/grafana/download
5 啟動
5.1 先啟動 Pushgateway
通過cmd啟動 pushgateway.exe
5.2 再啟動Prometheus
通過cmd啟動prometheus.exe
5.3 啟動flink
5.4 啟動Grafana
通過cmd啟動grafana-server.exe
5.4.2 配置Grafana
配置資料來源
Grafana預設執行在3000埠。使用預設使用者名稱密碼(admin/admin)登入Grafana後,選擇左側選單的Configuration -> Data Sources。
接下來點選右側的Add data source
按鈕。在資料來源型別選擇中介面選擇Prometheus
。
最後,將Prometheus的地址埠號填寫入URL這一欄,點選下方的Save & Test
按鈕。如果配置無誤,會彈出資料來源正常連線的提示資訊。
5.4.3 配置Dashboard
選擇左側選單的Create -> Dashboard,然後選擇Add Query
。
Dashboard的Add Panel,Add Query。會進入到指標查詢配置頁面。
開啟Query右側的下拉列表,選擇使用的資料來源。
接下來配置查詢語句。有以下兩種方式點選Metrics按鈕,根據分類選擇監控指標。或者是在文字框中輸入指標的關鍵字。查詢語句配置完畢後,頁面上方會顯示出監控資料,如圖所示。
返回Dashboard後可以看到配置的監控圖已經固定到了頁面當中,方便以後檢視。
作者:AlienPaul
連結:https://www.jianshu.com/p/5e91a1ac2959
來源:簡書
著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。