最新版Prometheus+Grafana+node-exporter炫酷界面


一、概述

理論知識就不多介紹了,參考鏈接:

https://www.cnblogs.com/xiao987334176/p/9930517.html

本文使用2台服務器,來搭建。

環境

操作系統 docker版本 ip 容器
centos 7.4 18.09.2 192.168.10.104 Prometheus+Grafana+node-exporter
centos 7.4 18.09.2 192.168.10.20 node-exporter

 

 

 

 

二、安裝

請確保2台服務器,已經安裝了docker。

163 docker鏡像

默認下載鏡像太慢了,需要更改為163

2台服務器都修改

vim /etc/docker/daemon.json

內容如下:

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

 

重啟docker

systemctl restart docker

 

node-exporter

2台服務器,都執行一下。用來收集服務器數據的

docker run -d -p 9100:9100 \
  -v "/proc:/host/proc:ro" \
  -v "/sys:/host/sys:ro" \
  -v "/:/rootfs:ro" \
  --net="host" \
  --restart=always \
  --name node-exporter \
  prom/node-exporter

 

Prometheus

新建目錄prometheus,編輯配置文件prometheus.yml

mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml

內容如下:

global:
  scrape_interval:     60s
  evaluation_interval: 60s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus
 
  - job_name: localhost
    static_configs:
      - targets: ['192.168.10.104:9100']
        labels:
          instance: localhost
  - job_name: server20
    static_configs:
      - targets: ['192.168.10.20:9100']
        labels:
          instance: server20

注意:修改IP地址

 

啟動prometheus

docker run  -d \
  -p 9090:9090 \
  -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  \
  --restart=always \
  --name prometheus \
  prom/prometheus

 

訪問頁面:

http://192.168.10.104:9090/targets

等待1分鍾,確保是up狀態

 

 

 

Grafana

新建空文件夾grafana-storage,用來存儲數據

mkdir /opt/grafana-storage

設置權限

chmod 777 -R /opt/grafana-storage

因為grafana用戶會在這個目錄寫入文件,直接設置777,比較簡單粗暴!

 

啟動grafana

docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -v /opt/grafana-storage:/var/lib/grafana \
  --restart=always \
  --name grafana \
  grafana/grafana

 

等待1分鍾,訪問url:

http://192.168.10.104:3000/

 

默認會先跳轉到登錄頁面,默認的用戶名和密碼都是admin

 

登錄之后,它會要求你重置密碼。你還可以再輸次admin密碼!

 

密碼設置完成之后,就會跳轉到首頁

 

 

點擊Add data source

 

 

點擊下面的Save & Test,如果出現綠色的,說明ok了

 

三、Node Exporter for Prometheus Dashboard 中文版 

訪問鏈接:

https://grafana.com/grafana/dashboards/8919/revisions

 

下載最新的

 

 

點擊import

 

 

點擊上傳

 

 

選擇下載好的json文件,選擇Prometheus

 

 

效果如下:

 

 是不是,看着很炫酷啊!!!

 

四、session問題

剛剛我用的是谷歌瀏覽器訪問的,沒啥問題。

但是我用 edge 瀏覽器,訪問時。輸入用戶名和密碼之后,還依然提示更改密碼。

這個時候,直接跳過即可。

但是進入之后,卻發現,數據都是空的!!!

 

 

點擊左側的admin,就可以看到session列表。

 

 

因此,只需要將谷歌瀏覽器的配置,導入進來即可。

 

點擊管理

 

 

選擇,點擊一下

 

 

就可以看到數據了

 

 

重新點擊,就可以看到面板了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM