Prometheus 集成 Node Exporter

文章首發於公衆號《程序員果果》 地址:mp.weixin.qq.com/s/40ULB9UWb…node

簡介

Prometheus 官方和一些第三方,已經把一些經常使用數據庫、系統、中間件等的指標數據的採集作成了一個個 exporter,在生產環境中,直接導入使用就能夠。 這一節,咱們就用 Prometheus 官方提供的 Node Exporter 來完成對Linux系統運行數據的採集 。linux

實驗

Node Exporter 安裝及運行

在一臺 Linux 機器上安裝並運行 Node Exporter,我使用的是一臺 ip 爲 172.16.2.101 的Linux 虛擬機。git

下載地址:github.com/prometheus/…程序員

下載並解壓:github

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
複製代碼

進入 node_exporter-0.18.1.linux-amd64 文件夾 啓動node_exporter:web

./node_exporter
複製代碼

Prometheus 配置

在 prometheus.yml 中配置 node_exporter 的metrics 端點,內容以下:docker

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:shell

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 發現已經出現了 target 「node_exporter」 ,而且爲UP狀態。數據庫

Grafana 導入 DashBoard

Grafana 官方和社區對已經作好了經常使用的 DashBoard,能夠訪問 grafana.com/grafana/das… 進行查詢:bash

選擇下載最多的,點擊進去:

DashBoard 的 id 爲 8919,後面要用到。

啓動 Grafana

docker start grafana
複製代碼

經過Grafana的 + 圖標導入(Import) Node Exporter dashboard:

  • grafana id = 8919
  • 注意選中prometheus數據源

點擊 "Import" 會跳轉到 監控界面:

經過界面能夠直觀的看到 主機cpu佔用率 、負載、磁盤空間、內存等信息。

總結

這一節 ,經過集成 Node Exporter 來演示了 exporter 的使用。以後你能夠利用Prometheus 官方提供的其餘 exporter 應用到你的學習或工做中,例如 MySQL Server Exporter 、Redis exporter 等等。

往期內容

關注我

相關文章
相關標籤/搜索