Prometheus+Grafana監控Linux主機

1、安裝Prometheus

1.1 、下載Prometheus

下載網址

https://github.com/prometheus/prometheus/releases

選擇需要的版本

wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gz

1.2、安裝Prometheus軟件

1.2.1、創建用戶組

groupadd prometheus
useradd -g prometheus -m -s /sbin/nologin prometheus

1.2.2、解壓配置

tar -zxvf prometheus-2.53.0.linux-amd64.tar.gz
mv prometheus-2.53.0.linux-amd64 /usr/local/prometheus
sed -i 's/localhost/ 172.25.0.166/g' /usr/local/prometheus/prometheus.yml

1.2.3、將Prometheus添加至系統環境變量

vim /etc/profile
export PROMETHEUS_HOME=/usr/local/prometheus
PATH=$PATH:$PROMETHEUS_HOME
export PATH

重載系統環境變量文件

source /etc/profile

1.2.4、查看Prometheus的版本信息

prometheus --version	

1.2.5、創建數據目錄

mkdir /usr/local/prometheus/data/

1.2.6、權限修改

chown -R prometheus.prometheus /usr/local/prometheus

1.2.7、檢查并加載配置文件

cd /usr/local/prometheus/
./promtool check config prometheus.yml

1.2.8、創建systemd服務

cat <<EOF > /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data/ --web.enable-lifecycle --storage.tsdb.retention.time=30d
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

參數注解:

  • config.file: 指定配置文件
  • web.enable-lifecycle: 支持通過http請求重載配置
  • storage.tsdb.path: 指定數據存儲目錄(默認當前目錄的的data目錄,若不存在則新建)
  • storage.tsdb.retention.time: 指定數據保留時間(默認15d)

1.2.9、啟動服務

systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus && systemctl enable prometheus

1.2.10、確認端口已經被監聽

ss -lnput | grep 9090
tcp     LISTEN   0        512                    *:9090                *:*       users:(("prometheus",pid=20863,fd=7))

1.2.11、檢查并加載配置文件

http://172.25.0.166:9090/metrics

在這里插入圖片描述


2、監控Linux主機

2.1 、在Linux主機安裝exporter插件

2.1.1、下載node_exporter

下載網址

https://github.com/prometheus/node_exporter/releases

下載需要的版本

wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz

2.1.2、創建用戶組

groupadd prometheus
useradd -g prometheus -m -s /sbin/nologin prometheus

2.1.3、安裝并解壓

tar -zxvf node_exporter-1.8.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.8.1.linux-amd64  node_exporter

2.1.4、權限修改

chown -R prometheus.prometheus /usr/local/node_exporter

2.1.5、將node_exporter執行文件目錄添加至環境變量

vim /etc/profile
export NODE_EXPORTER=/usr/local/node_exporter
export PATH=$PATH:$NODE_EXPORTER
export PATH

重載系統環境變量文件

source /etc/profile

2.1.6、創建systemd服務

cat > /usr/lib/systemd/system/node_exporter.service <<EOF[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

2.1.7、啟動服務

systemctl daemon-reload
systemctl enable node_exporter && systemctl start node_exporter
systemctl status node_exporter

2.1.8、確認端口已經被監聽

ss -lnput | grep 9100
tcp     LISTEN   0        512                    *:9100                *:*       users:(("node_exporter",pid=21904,fd=3))

2.2、將Linux主機的exporter插件添加至Prometheus軟件服務

修改Prometheus配置文件

vim /usr/local/prometheus/prometheus.yml
scrape_configs:
... - job_name: 'Linux Node'					# 添加監控項的名字static_configs:							- targets: ['172.25.0.166:9100']		# 監控主機的ip地址和端口號

重啟prometheus服務

systemctl restart prometheus

2.3 、測試Prometheus的監控Linux主機狀態

http://172.25.0.166:9090/targets?search=&scrapePool=Linux+Node

在這里插入圖片描述

http://172.25.0.166:9100/metrics

在這里插入圖片描述


3、使用Grafana展示數據

3.1、下載grafana

下載網址

https://grafana.com/grafana/download

下載需要的版本

wget  https://dl.grafana.com/enterprise/release/grafana-enterprise-11.1.0-1.x86_64.rpm

3.2、安裝grafana

rpm -ivh grafana-enterprise-11.1.0-1.x86_64.rpm

3.3、啟動grafana

systemctl daemon-reload 
systemctl enable grafana-server && systemctl start grafana-server

3.4、grafana中文化

vim /etc/grafana/grafana.ini
[users]
# 設置默認語言為中文 
default_language = zh-Hans

重啟服務

systemctl restart grafana-server

3.5、下載導入grafana模板

https://grafana.com/grafana/dashboards/15172-node-exporter-for-prometheus-dashboard-based-on-11074/

在這里插入圖片描述

3.6、加載grafana-piechart-panel插件

grafana-cli plugins install grafana-piechart-panel

tar -xvf grafana-piechart-panel.tar.gz
mv grafana-piechart-panel /var/lib/grafana/plugins/grafana-piechart-panel

3.7、瀏覽器訪問

在這里插入圖片描述


4、參考文獻

https://prometheus.io/
https://blog.csdn.net/heian_99/article/details/126989356
https://www.cnblogs.com/saneri/p/14667301.html
https://blog.csdn.net/qq_31725371/article/details/114697770

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/44974.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/44974.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/44974.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

解決鴻蒙開發中克隆項目無法簽名問題

文章目錄 問題描述問題分析解決方案 問題描述 在一個風和日麗的早晨&#xff0c;這是我學習鴻蒙開發的第四天&#xff0c;把文檔過了一遍的我準備看看別人的項目學習一下&#xff0c;于是就用git去clone了一個大佬的開源項目&#xff0c;在簽名的時候遇到了問題&#xff1a; h…

在攻防演練中遇到的一個“有馬蜂的蜜罐”

在攻防演練中遇到的一個“有馬蜂的蜜罐” 有趣的結論&#xff0c;請一路看到文章結尾 在前幾天的攻防演練中&#xff0c;我跟隊友的氣氛氛圍都很好&#xff0c;有說有笑&#xff0c;恐怕也是全場話最多、笑最多的隊伍了。 也是因為我們遇到了許多相當有趣的事情&#xff0c;其…

Spring JDBC 具名參數用法

Spring JDBC中具名參數的用法 maven引入Spring jdbc <dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.19</version></dependency> 在Spring配置中配置 <!-…

【leetcode】滑動窗口專題

文章目錄 1.長度最小的子數組2.無重復字符的最長子串3.最大連續1的個數III4.將x減小到0的最小操作數5.水果成籃6.找到字符串中所有字母異位詞7.串聯所有單詞的子串8.最小覆蓋子串 1.長度最小的子數組 leetcode 209.長度最小的子數組 看到這個題目&#xff0c;第一眼肯定想到的…

正則表達式控制everything等搜索工具更快速的對需要的內容進行檢索

正則表達式對文件搜索工具規則 表格模式 匹配模式描述abgr(ale)y匹配 “gray” 或 “grey”.匹配除換行符之外的任意單個字符[abc]匹配字符 “a”、“b” 或 “c” 中的任意一個[^abc]匹配除了 “a”、“b”、“c” 之外的任意單個字符[a-z]匹配小寫字母 a 到 z 之間的任意一…

科普文:深入理解Mybatis

概敘 (1) JDBC JDBC(Java Data Base Connection,java數據庫連接)是一種用于執行SQL語句的Java API,可以為多種關系數據庫提供統一訪問,它由一組用Java語言編寫的類和接口組成.JDBC提供了一種基準,據此可以構建更高級的工具和接口,使數據庫開發人員能夠編寫數據庫應用程序。 優點…

Vue3 + Echarts堆疊折線圖的tooltip不顯示問題

問題介紹 使用Echarts在Vue3Vite項目中繪制堆疊折線圖的的時候&#xff0c;tooltip總是不顯示&#xff0c;經過很長時間的排查和修改&#xff0c;最后發現是在使用上有錯誤導致的。 錯誤圖片展示 問題原因 由于Vue3底層使用proxy代理創建示例&#xff0c;使用其創建出來的實…

RDD 專項練習

RDD 專項練習 現有分數信息文件 scores.txt 班級ID 姓名 年齡 性別 科目 成績 12 張三 25 男 chinese 50 12 張三 25 男 math 60 12 張三 25 男 english 70 12 李四 20 男 chinese 50 12 李四 20 男 math 50 12 李四 20 男 english 50 12 王芳 19 女 chinese 70 12 王芳 19 女…

FPGA-Verilog-Vivado-軟件使用

這里寫目錄標題 1 軟件配置2 FPGA-7000使用2.1 運行啟動方式 1 軟件配置 編輯器綁定為Vscode&#xff0c;粘貼VS code運行文件的目錄&#xff0c;后綴參數保持不變&#xff1a; 如&#xff1a; D:/Users/xdwu/AppData/Local/Programs/Microsoft VS Code/Code.exe [file name]…

從技術到管理:你必須知道的七個轉變

在職業生涯的道路上&#xff0c;很多技術骨干會逐步轉向管理崗位。這不僅是職位的晉升&#xff0c;更是角色、思維和能力的全方位轉變。以下是七個關鍵的轉變&#xff0c;幫助技術人員順利完成這一跨越。 一、從個人貢獻者到團隊領導者的轉變 在技術崗位上&#xff0c;成功往…

(19)夾鉗(用于送貨)

文章目錄 前言 1 常見的抓手參數 2 參數說明 前言 Copter 支持許多不同的抓取器&#xff0c;這對送貨應用和落瓶很有用。 按照下面的鏈接&#xff08;或側邊欄&#xff09;&#xff0c;根據你的設置了解配置信息。 Electro Permanent Magnet v3 (EPMv3)Electro Permanent M…

bug記錄 qInstallMessageHandler的使用

QT (純C)項目 ‘Qxxx‘ file not found 和 編譯報錯問題(已解決)_qt頭文件file not found-CSDN博客 qInstallMessageHandler&#xff08;指針函數參數&#xff09; 需要靜態指針&#xff0c;這個函數 #include <iostream> #include "singleton.h" #include &…

Linux操作系統CentOS如何更換yum鏡像源

簡介 CentOS&#xff0c;是基于Red Hat Linux提供的可自由使用源代碼的企業級Linux發行版本&#xff1b;是一個穩定&#xff0c;可預測&#xff0c;可管理和可復制的免費企業級計算平臺。 下載地址: centos安裝包下載_開源鏡像站-阿里云 相關倉庫&#xff1a; CentOS過期源&…

職業教育人工智能實驗實訓室建設應用案例

隨著人工智能技術的快速發展&#xff0c;其在職業教育領域的應用逐漸深入。唯眾作為一家專注于教育技術領域的企業&#xff0c;積極響應國家關于人工智能教育的政策號召&#xff0c;通過建設人工智能實驗實訓室&#xff0c;為學生提供了一個實踐操作與創新思維相結合的學習平臺…

C++ STL iter_swap用法和實現

一&#xff1a;功能 交換兩個迭代器指向的元素值&#xff0c;一般用在模板中 二&#xff1a;使用 #include <vector> #include <iostream>template <typename It, typename Cond>requires std::forward_iterator<It> && std::indirectly_swa…

富格林:曝光糾正安全交易誤區

富格林指出&#xff0c;貴金屬投資是許多投資者追求資產多樣化和風險管理的重要途徑。然而&#xff0c;正如任何投資領域一樣&#xff0c;不少投資者也對貴金屬投資產生了一些誤區和錯誤觀念。但事實上&#xff0c;如果這種誤區一直伴隨著我們的交易進程&#xff0c;是很難做到…

34 超級數據查看器 關聯圖片

超級數據查看器app&#xff08;excel工具&#xff0c;數據庫軟件&#xff0c;表格app&#xff09; 關聯圖片講解 點擊 打開該講的視頻 點擊訪問app下載頁面 豌豆莢 下載地址 大家好&#xff0c;今天我們講一下超級數據查看器的關聯圖片功能 這個功能能讓表中的每一條信息&…

數據結構-散列表(hash table)

6.1 散列表的概念 散列表又叫哈希&#xff08;hash&#xff09;表&#xff0c;是根據鍵&#xff08;key&#xff09;直接訪問在內存存儲位置的值&#xff08;value&#xff09;的數據結構&#xff0c;由數組演化而來&#xff08;根據數組支持按照下標進行隨機訪問數據的特性&a…

windows腳本獲取 svn版本號

簡介 需要使用項目中svn的最新版本號 命令 set svnURL"URL" svn info %svnURL% | findstr "Revision:" > Version.txt for /f "token2 delims " %%i in (Version.txt) do set rev%%i echo %rev% pause

力扣爆刷第163天之TOP100五連刷81-85(回文鏈表、路徑和、最長重復子數組)

力扣爆刷第163天之TOP100五連刷81-85&#xff08;回文鏈表、路徑和、最長重復子數組&#xff09; 文章目錄 力扣爆刷第163天之TOP100五連刷81-85&#xff08;回文鏈表、路徑和、最長重復子數組&#xff09;一、234. 回文鏈表二、112. 路徑總和三、169. 多數元素四、662. 二叉樹…