完整步驟
1.啟動(dòng) Prometheus 普羅米修斯?
prometheus --config.file=/usr/local/etc/prometheus.yml
瀏覽器訪問?
http://localhost:9090/targets
?2.啟動(dòng)Node_exporter?
node_exporter
訪問:
http://localhost:9100
??3.啟動(dòng)grafana
brew services start grafana
訪問
http://localhost:
3000?4.添加數(shù)據(jù)源
5.查看Dashboard?
一、搭建Node_exporter+Prometheus+Grafana監(jiān)控系統(tǒng)
?普羅米修斯是后端數(shù)據(jù)監(jiān)控平臺(tái),通過Node_exporter收集數(shù)據(jù),Grafana將數(shù)據(jù)用圖形的方式展示出來
?1. Prometheus安裝
官網(wǎng)各平臺(tái)下載?
(1)通過brew安裝
brew install prometheus
(2)驗(yàn)證Prometheus
prometheus --version
(3)查看安裝位置
which prometheus
找到默認(rèn)配置prometheus.yml的位置?
/usr/local/etc/prometheus.yml
(4)啟動(dòng)Prometheus?server
prometheus --config.file=/usr/local/etc/prometheus.yml
啟動(dòng)后瀏覽器輸入: http://localhost:9090/targets
http://localhost:9090/targets
查看監(jiān)控?cái)?shù)據(jù)?
http://localhost:9090/metrich
查看到這個(gè)頁面:
(5)配置Prometheus
- 在Prometheus.yml(/usr/local/etc/prometheus.yml)中有配置文件,我們可以對(duì)其進(jìn)行配置,當(dāng)然第一次安裝也可以不管;
配置后重啟服務(wù)才能生效?
默認(rèn)配置:
告警管理器(Alertmanager)的配置,目前還沒有安裝Alertmanager,可以提前配置好:
# 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"
注意輸入的格式:yaml格式校驗(yàn)?
修改后如下:
其大致可分為四部分:
- global:全局配置,其中scrape_interval表示抓取一次數(shù)據(jù)的間隔時(shí)間,evaluation_interval表示進(jìn)行告警規(guī)則檢測(cè)的間隔時(shí)間;
- alerting:告警管理器(Alertmanager)的配置,目前還沒有安裝Alertmanager;
- rule_files:告警規(guī)則有哪些;
- scrape_configs:抓取監(jiān)控信息的目標(biāo)。一個(gè)job_name就是一個(gè)目標(biāo),其targets就是采集信息的IP和端口。這里默認(rèn)監(jiān)控了Prometheus自己,可以通過修改這里來修改Prometheus的監(jiān)控端口。Prometheus的每個(gè)exporter都會(huì)是一個(gè)目標(biāo),它們可以上報(bào)不同的監(jiān)控信息,比如機(jī)器狀態(tài),或者mysql性能等等,不同語言sdk也會(huì)是一個(gè)目標(biāo),它們會(huì)上報(bào)你自定義的業(yè)務(wù)監(jiān)控信息。
重載?prometheus
prometheus --config.file=/usr/local/etc/prometheus.yml
(6)監(jiān)聽 9090 端口
?查看端口是否被占用?
lsof -i :端口號(hào)
殺掉進(jìn)程
kill PID //或者 kill -9 PID
- 訪問prometheus
- 輸入: “ip地址”+":9090" 在瀏覽器中進(jìn)行訪問,如果出現(xiàn)可視化界面說明成功;
示例: 192.168.10.8:9090 直接在自己電腦中訪問
如果訪問不了,請(qǐng)檢查防火墻是否開啟9090端口 ,或者端口是否被占用
2.Node_exporter安裝?
機(jī)器狀態(tài)監(jiān)控(監(jiān)控服務(wù)器CPU,硬盤,網(wǎng)絡(luò)等狀態(tài))?
下載?windows的 node_expoeter
(1)通過 Brew安裝
安裝:?
brew install node_exporter
驗(yàn)證:
node_exporter --version
?
(2)啟動(dòng) node_exporter?
brew services start node_exporter
?關(guān)閉服務(wù)
brew services stop node_exporter
或者直接?
node_exporter
關(guān)閉終端窗口就關(guān)閉服務(wù)了
(3)監(jiān)聽9100端口
- 本Centos中訪問:?
curl http://localhost:9100/metrics
- 電腦瀏覽器中訪問:?
ip地址:9100
本地訪問:http://localhost:9100
?
如果訪問有內(nèi)容顯示則成功
啟動(dòng)服務(wù)的時(shí)候可使用nohup后臺(tái)啟動(dòng),如果是直接圖中所示內(nèi)容啟動(dòng)則重開連接
(4)配置Prometheus.yml
?從? 上面的1( 3)? 可知路徑:
/usr/local/etc/prometheus.yml
添加配置scrape_configs部分如下:?
注意輸入的格式:yaml格式校驗(yàn)??
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "Node"
static_configs:
- targets: ["192.168.10.22:9100"]
?重載配置:
prometheus --config.file=/usr/local/etc/prometheus.yml?
瀏覽器查看:
http://localhost:9090/targets
?(5)修改端口
如果未能啟動(dòng)成功,提示端口被占用,需要修改默認(rèn)端口
node_exporter --web.listen-address=:9199
prometheus.yml的端口也要修改為9100 也要修改為 9199
(6)?查看端口是否被占用
lsof -i :端口號(hào)
殺進(jìn)程
kill PID
??3.Grafana安裝
(1)通過 brew安裝?
brew install grafana
查看插件的安裝路徑?
ps aux|grep grafana
配置文件的位置
/usr/local/etc/grafana/grafana.ini
(2)插件安裝
默認(rèn)安裝位置
/usr/local/var/lib/grafana/plugins
?當(dāng)grafana自帶的圖標(biāo)等不等滿足我們的需求時(shí),比如grafana默認(rèn)的圖片是沒有餅圖的。
可以安裝piechart餅狀圖插件
先了解下? grafana cli
grafana cli --help
官網(wǎng)查看插件
命令查看可用的插件:
grafana cli plugins list-remote
?
插件有:
grafana-clock-panel
grafana-guidedtour-panel
grafana-polystat-panel
grafana-xyzchart-panel?
本人安裝的版本沒有g(shù)rafana-piechart-panel,所以安裝了grafana-clock-panel
grafana cli plugins install grafana-clock-panel
(3)啟動(dòng)grafana
brew services start grafana
關(guān)閉服務(wù)
brew services stop grafana
-
安裝并啟動(dòng)Grafana后,瀏覽器輸入 IP:3000 來訪問Grafana,管理員賬號(hào)密碼默認(rèn)是admin/admin。首次登陸會(huì)讓你修改管理員密碼,不修改也可以,進(jìn)入后還能修改。
-
本地訪問
http://localhost:
3000
?
二、監(jiān)控使用
1. 在grafana添加數(shù)據(jù)源?
?
先輸入名稱,然后填入http://ip:9090,然后直接點(diǎn)Save&Test
2. 添加模板
模板?
點(diǎn)擊Dashboards?,可選擇一個(gè),也可多個(gè)import
-
選擇左側(cè)邊欄,Dashboards,New--Imput, 在Grafana.com Dashboard中輸入: 8919或者 1860或者 11074
也可以自己選擇官方展示面板,鏈接: https://grafana.com/dashboards
?
3. 查看效果
ID:8918?
ID:?1860?
ID 11074
黃色警告部分的原因 :一般是grafana的版本和舊版的panel plugins的兼容問題
三、搭建其他服務(wù)器監(jiān)控系統(tǒng)
監(jiān)控系統(tǒng)的Prometheus類似于一個(gè)注冊(cè)中心,我們可以只需要配置一個(gè)Prometheus,而在其他服務(wù)器,只需要安裝node_exporter,它們的數(shù)據(jù)流轉(zhuǎn)就是通過exporter采集數(shù)據(jù)信息,然后告訴prometheus它的位置;而Prometheus則存儲(chǔ)exporter的信息供Grafana詢問;Grafana則負(fù)責(zé)信息的展示;所以可以只配置一個(gè)Prometheus,而其他服務(wù)器或者本機(jī)的服務(wù)器的exporter只需要在這一個(gè)Promethes中給出它的job_name,targets地址等信息即可;
Node_exporter安裝在被測(cè)服務(wù)器上,啟動(dòng)服務(wù)
- 各步驟的IP地址要換為被測(cè)服務(wù)器的IP地址
- Prometheus.yml的 targets值
- 網(wǎng)頁訪問的ip部分
- grafana添加數(shù)據(jù)源的URL
注意:如果需要監(jiān)控其他服務(wù)器,則只需要在其他服務(wù)器安裝 node_exporter 即可,將其對(duì)應(yīng)的ip地址,端口號(hào)等信息配置到已有的Prometheus的Prometheus.yml內(nèi)即可;格式參照其他,job_name不能命名成一樣的,可改成其他名稱;Grafana添加數(shù)據(jù)源和注冊(cè)儀表盤都是一致的;文章來源:http://www.zghlxwxcb.cn/news/detail-858826.html
參考:windows的Grafana監(jiān)控系統(tǒng)搭建?文章來源地址http://www.zghlxwxcb.cn/news/detail-858826.html
到了這里,關(guān)于(mac)Prometheus監(jiān)控之Node_exporter(CPU、內(nèi)存、磁盤、網(wǎng)絡(luò)等)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!