環(huán)境
linux: centos7.6
prometheus: 2.13.1.linux-amd64
- 基于時(shí)間序列的數(shù)值數(shù)據(jù)的容器監(jiān)控解決方案: 自帶了數(shù)據(jù)存儲(chǔ)和監(jiān)控,是k8s官方指定監(jiān)控方案。
node_exporter: 0.18.1.linux-amd64
- 用于采集服務(wù)器層面的運(yùn)行指標(biāo),然后轉(zhuǎn)為prometheus能夠識(shí)別的格式,然后建立監(jiān)聽等中央服務(wù)主動(dòng)來抓取數(shù)據(jù)
process-exporter: 0.5.0.linux-amd64
- 主要用于監(jiān)控服務(wù)進(jìn)程的,也是將數(shù)據(jù)轉(zhuǎn)為固定格式,等中央服務(wù)器主動(dòng)來抓取
grafana: 6.4.3.linux-amd64 >>>官方文檔https:///docs/grafana/latest/
- 一個(gè)成熟完整的展示數(shù)據(jù)的工具,可以整個(gè)市場(chǎng)大部分的數(shù)據(jù)源
準(zhǔn)備安裝包
prometheus-2.13.1.linux-amd64.tar.gz
process-exporter-0.5.0.linux-amd64.tar.gz
node_exporter-0.18.1.linux-amd64.tar.gz
grafana-6.4.3.linux-amd64.tar.gz
安裝prometheus
下載最新版本,并解壓
下載地址:https:///download/
tar xvfz prometheus-*.tar.gz
cd prometheus-*
以下是基本的配置,完整文檔介紹可以看 > 官方文檔:https:///docs/prometheus/2.13/configuration/configuration/
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 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'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
如果后面配置了exporter組件,可以在scrape_configs里添加job,例如:
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
啟動(dòng)
# Start Prometheus.
# 默認(rèn)情況下,Prometheus會(huì)將其數(shù)據(jù)庫(kù)存儲(chǔ)在./data (flag—storage.tsdb.path)中
$ cd prometheus-2.13.1.linux-amd64/
$ nohup ./prometheus --config.file=prometheus.yml >/dev/null &
- 驗(yàn)證:可以通過http://ip:9090訪問瀏覽器,或者h(yuǎn)ttp://ip:9090/metrics看是否能提供關(guān)于自身的各項(xiàng)指標(biāo)
安裝node_exporter
下載二進(jìn)制安裝包,安裝并啟動(dòng)
wget https://github.com/prometheus/node_exporter/releases/download/v*/node_exporter-*.*-amd64.tar.gz
tar xvfz node_exporter-*.*-amd64.tar.gz
cd node_exporter-*.*-amd64
nohup ./node_exporter >/dev/null &
- 啟動(dòng)不需要帶配置文件,此時(shí)服務(wù)器會(huì)有9100的監(jiān)聽端口。
- 驗(yàn)證: 可以通過訪問瀏覽器http://ip:9100/metrics訪問服務(wù)器運(yùn)行指標(biāo)
安裝process_exporter
下載二進(jìn)制安裝包
$ wget https://github.com/ncabatoff/process-exporter/releases/download/v0.5.0/process-exporter-0.5.0.linux-amd64.tar.gz
$ tar -xvf process-exporter-0.5.0.linux-amd64.tar.gz
$ ll
-rw-r--r-- 1 3434 3434 1076 Apr 14 2019 LICENSE
-rwxr-xr-x 1 3434 3434 7681088 Apr 14 2019 process-exporter
-rw-r--r-- 1 3434 3434 12958 Apr 14 2019 README.md
- 這個(gè)解壓完后默認(rèn)是沒有配置文件的,需要我們自己寫一個(gè),啟動(dòng)時(shí)通過-config.path 指定配置文件。
讀配置文件的本質(zhì)就是,讀里面配置的服務(wù)名,通過服務(wù)名稱去進(jìn)行pid的查找和分析,以下為范例<這里使用{{.Matches}}模板>匹配mysql和prometheus兩個(gè)服務(wù):
$ vim process.yaml
process_names:
- name: "{{.Matches}}"
cmdline:
- 'mysqld'
- name: "{{.Matches}}"
cmdline:
- 'prometheus'
啟動(dòng)
# Start process_exporter.
nohup ./process-exporter -config.path process.yaml >/dev/null &
- 驗(yàn)證:訪問瀏覽器http://ip:9256/metrics ,會(huì)返回配置文件里指定的服務(wù)進(jìn)程信息
安裝grafana
下載二進(jìn)制安裝包
wget https://dl./oss/release/grafana-6.4.3.linux-amd64.tar.gz
tar -zxvf grafana-6.4.3.linux-amd64.tar.gz
啟動(dòng)
- 這里使用官方說明的二進(jìn)制啟動(dòng)方式,有點(diǎn)忒簡(jiǎn)單了,正式項(xiàng)目建議都配置為system系統(tǒng)服務(wù)
$ cd grafana-6.4.3
$ nohup ./bin/grafana-server web >/dev/null &
- 驗(yàn)證:訪問瀏覽器http://ip:3000, 默認(rèn)的賬號(hào)密碼為: admin / admin
使用grafana配置prometheus數(shù)據(jù)源
進(jìn)入grafana管理頁(yè)面
配置prometheus數(shù)據(jù)源
- 點(diǎn)擊左邊齒輪圖標(biāo)————>> Add data source —————>>點(diǎn)擊prometheus
- 拉到最下面點(diǎn)擊 Save&Test, 然后再點(diǎn)齒輪就可以看到配置的數(shù)據(jù)源了
添加儀表盤<可直接看最后一步>
- 點(diǎn)擊左邊的加號(hào)圖標(biāo)————>>點(diǎn)擊Choose Visualization(添加儀表盤)
給儀表盤添加數(shù)據(jù)源<可直接看最后一步>
- 點(diǎn)擊左邊的方塊圖標(biāo)————>>選擇剛保存的儀表盤————>>點(diǎn)擊儀表盤的Title
使用現(xiàn)有儀表盤模板
- 點(diǎn)擊左邊加好圖標(biāo)————>>import————>>在Grafana.com Dashboard中填入8919,然后等待幾秒ok
|