?k8s監(jiān)控方案:prometheus+exporter+grafana
官方文檔:
https://prometheus.io/docs/introduction/first_steps/
https://prometheus.io/docs/guides/node-exporter/
https://grafana.com/docs/grafana/latest/guides/getting_started/
1.Prometheus安裝步驟
(1)下載并解壓Prometheus到k8s的master機器
Prometheus下載地址:
解壓:
tar xvfz prometheus-*.tar.gz
cd prometheus-*
(2)配置
查看prometheus.yml,修改和添加以下配置:
scrape_configs:
? # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
? - job_name: '
node-admin-10.4.64.39'? ? #配置k8s的master和所有node的name和ip:port,格式如下? ? static_configs:
? ? - targets: ['
localhost:9090']? - job_name: '
node1-10.4.65.154'? ? static_configs:
? ? - targets: ['
10.4.65.154:9100']
(3)啟動prometheus?
./prometheus --config.file=prometheus.yml
(4)訪問prometheus?
本地瀏覽器訪問:
(5)查看監(jiān)控指標
-- status->?Targets 查看node節(jié)點運行情況(此時所有的node都是down,因為還沒有部署agent)
-- 下圖中1查看所有監(jiān)控指標
-- 下圖中2執(zhí)行監(jiān)控指標
-- 下圖中3圖形化展示監(jiān)控指標

2.Prometheus Node Exporter安裝步驟
Prometheus Node Exporter需要部署在所有的node機器上。安裝步驟如下:
(1)Prometheus Node Exporter下載地址
(2)安裝步驟
tar xvfz node_exporter-*.*-amd64.tar.gz
cd node_exporter-*.*-amd64
nohup ./node_exporter &?
您應該看到如下所示的輸出,指示節(jié)點導出器正在運行并在端口9100上公開指標:
INFO[0000] Listening on :9100? source="node_exporter.go:111"
驗證安裝是否成功:
curl http://localhost:9100/metrics
輸出如下,表示成功:
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summarygo_gc_duration_seconds{quantile="0"} 3.8996e-05
go_gc_duration_seconds{quantile="0.25"} 4.5926e-05
go_gc_duration_seconds{quantile="0.5"} 5.846e-05# etc.
(3)重啟prometheus (如需要)
netstat -nap | grep 9090? ?#查看prometheus 的進程號
kill -9 PID? ? #關閉prometheus 的進程
./prometheus --config.file=./prometheus.yml? ? #重啟prometheus??
(4)驗證node_exporter的數(shù)據(jù)被正確收集
?http:// localhost:9090
?status->?Targets中所有Endpoint 的state為up
3.Grafana安裝步驟
Grafana部署在prometheus的master同一機器上
(1)Grafana下載地址,并按照說明進行安裝
(2)啟動Grafana
sudo service grafana-server start
(3)瀏覽器訪問Grafana
http://ip:3000
用戶名/密碼:admin/admin
(4)Grafana基本配置
* 添加Data Sources
? ? - 在Dashboards中,點擊Data Sources,單擊+ Add data source
? ? - 選擇Prometheus

? ? - 添加name,URL,sava&test

* 根據(jù)需要導入展示模板
? ? - 查看所有模板:https://grafana.com/grafana/dashboards?dataSource=prometheus&search=node_exporter
? ? - 選擇需要的模板

? ? - 進入模板后,復制模板ID

? ? - import模板:



(5)Grafana數(shù)據(jù)展示
可根據(jù)需要展示的數(shù)據(jù),添加panel。
可根據(jù)需要拖動panel的位置。
