文章首發(fā)于公眾號《程序員果果》
地址:https://mp.weixin.qq.com/s/40ULB9UWbXVA21MxqnjBxw
簡介
Prometheus 官方和一些第三方,已經(jīng)把一些常用數(shù)據(jù)庫、系統(tǒng)、中間件等的指標(biāo)數(shù)據(jù)的采集做成了一個個 exporter,在生產(chǎn)環(huán)境中,直接導(dǎo)入使用就可以。 這一節(jié),我們就用 Prometheus 官方提供的 Node Exporter 來完成對Linux系統(tǒng)運(yùn)行數(shù)據(jù)的采集 。
實(shí)驗(yàn)
Node Exporter 安裝及運(yùn)行
在一臺 Linux 機(jī)器上安裝并運(yùn)行 Node Exporter,我使用的是一臺 ip 為 172.16.2.101 的Linux 虛擬機(jī)。
下載地址:https://github.com/prometheus/node_exporter/releases
下載并解壓:
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar zxvf node_exporter-0.18.1.linux-amd64.tar.gz
進(jìn)入 node_exporter-0.18.1.linux-amd64 文件夾 啟動node_exporter:
./node_exporter
Prometheus 配置
在 prometheus.yml 中配置 node_exporter 的metrics 端點(diǎn),內(nèi)容如下:
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_timeout: 5s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'linux-exporter'
metrics_path: /metrics
static_configs:
- targets: ['172.16.2.101:9100']
啟動 prometheus:
docker run --name prometheus -d -p 9090:9090 -v /root/prometheus-data:/prometheus-data \
prom/prometheus --web.enable-lifecycle --config.file=/prometheus-data/prometheus.yml
訪問 http://172.16.2.101:9090/targets 發(fā)現(xiàn)已經(jīng)出現(xiàn)了 target “node_exporter” ,并且為UP狀態(tài)。

Grafana 導(dǎo)入 DashBoard
Grafana 官方和社區(qū)對已經(jīng)做好了常用的 DashBoard,可以訪問 https://grafana.com/grafana/dashboards 進(jìn)行查詢:

選擇下載最多的,點(diǎn)擊進(jìn)去:

DashBoard 的 id 為 8919,后面要用到。
啟動 Grafana
docker start grafana
通過Grafana的 + 圖標(biāo)導(dǎo)入(Import) Node Exporter dashboard:
- grafana id = 8919
- 注意選中prometheus數(shù)據(jù)源


點(diǎn)擊 "Import" 會跳轉(zhuǎn)到 監(jiān)控界面:

通過界面可以直觀的看到 主機(jī)cpu占用率 、負(fù)載、磁盤空間、內(nèi)存等信息。
總結(jié)
這一節(jié) ,通過集成 Node Exporter 來演示了 exporter 的使用。之后你可以利用Prometheus 官方提供的其他 exporter 應(yīng)用到你的學(xué)習(xí)或工作中,例如 MySQL Server Exporter 、Redis exporter 等等。