目錄
一、普羅米修斯概述
Prometheus(由go語言(golang)開發)是一套開源的監控&報警&時間序列數 據庫的組合。適合監控docker容器。因為kubernetes(俗稱k8s)的流行帶動 了prometheus的發展。
https://prometheus.io/docs/introduction/overview/
二、時間序列數據
1、什么是序列數據
時間序列數據(TimeSeries Data) : 按照時間順序記錄系統、設備狀態變化 的數據被稱為時序數據。
應用的場景很多, 如:
- 無人駕駛車輛運行中要記錄的經度,緯度,速度,方向,旁邊物體的距 離等等。每時每刻都要將數據記錄下來做分析。
- 某一個地區的各車輛的行駛軌跡數據
- 傳統證券行業實時交易數據
- 實時運維監控數據等
2、時間序列數據特點
- 性能好
關系型數據庫對於大規模數據的處理性能糟糕。NOSQL可以比較好的處理 大規模數據,讓依然比不上時間序列數據庫。
- 存儲成本低
高效的壓縮算法,節省存儲空間,有效降低IO
Prometheus有着非常高效的時間序列數據存儲方法,每個采樣數據僅僅占 用3.5byte左右空間,上百萬條時間序列,30秒間隔,保留60天,大概花了 200多G(來自官方數據)
3、Prometheus的主要特征
多維度數據模型 靈活的查詢語言 不依賴分布式存儲,單個服務器節點是自主的 以HTTP方式,通過pull模型拉去時間序列數據 也可以通過中間網關支持push模型 通過服務發現或者靜態配置,來發現目標服務對象 支持多種多樣的圖表和界面展示
4、普羅米修斯原理架構圖
三、實驗環境准備
服務器 | IP地址 |
Prometneus服務器 | 192.168.116.129 |
被監控服務器 | 192.168.116.130 |
grafana服務器 | 192.168.116.131 |
教程使用的軟件:鏈接: https://pan.baidu.com/s/1QV4KYZksyIp65UsScioq4Q 提取碼: vcej
失效可聯系我
1. 靜態ip(要求能上外網)
2. 主機名
各自配置好主機名
# hostnamectl set-hostname --static server.cluster.com
三台都互相綁定IP與主機名
# vim /etc/hosts
192.168.116.129 master
192.168.116.130 node1
192.168.116.131 node2
echo "192.168.116.129 master
192.168.116.130 node1
192.168.116.131 node2">>/etc/hosts
3. 時間同步(時間同步一定要確認一下)
yum install -y ntpdate && ntpdate time.windows.com
4. 關閉防火牆,selinux
# systemctl stop firewalld
# systemctl disable firewalld
# iptables -F
1、安裝prometheus
從 https://prometheus.io/download/ 下載相應版本,安裝到服務器上
官網提供的是二進制版,解壓就能用,不需要編譯
上傳prometheus-2.5.0.linux-amd64.tar.gz
tar -zxvf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-2.5.0.linux-amd64/ /usr/local/prometheus
直接使用默認配置文件啟動
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
確認端口(9090)
ss -anltp | grep 9090
2、prometheus界面
通過瀏覽器訪問http://服務器IP:9090就可以訪問到prometheus的主界面
默認只監控了本機一台,點Status --》點Targets --》可以看到只監控了本 機
3、主機數據展示
通過http://服務器IP:9090/metrics可以查看到監控的數據
在web主界面可以通過關鍵字查詢監控項
4、監控遠程Linux主機
① 在遠程linux主機(被監控端agent1)上安裝node_exporter組件
下載地址: https://prometheus.io/download/
上傳node_exporter-0.16.0.linux-amd64.tar.gz
tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/node_exporter
里面就一個啟動命令node_exporter,可以直接使用此命令啟動
nohup /usr/local/node_exporter/node_exporter &
確認端口(9100)
擴展: nohup命令: 如果把啟動node_exporter的終端給關閉,那么進程也會 隨之關閉。nohup命令會幫你解決這個問題。
② 通過瀏覽器訪問http://被監控端IP:9100/metrics就可以查看到 node_exporter在被監控端收集的監控信息
③ 回到prometheus服務器的配置文件里添加被監控機器的配置段
在主配置文件最后加上下面三行
vim /usr/local/prometheus/prometheus.yml
- job_name: 'node1'
static_configs:
- targets: ['192.168.116.130:9100']
- job_name: 'agent1' # 取一個job名稱來代 表被監控的機器
static_configs:
- targets: ['10.1.1.14:9100'] # 這里改成被監控機器 的IP,后面端口接9100
改完配置文件后,重啟服務
pkill prometheus
確認端口沒有進程占用
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
確認端口被占用,說 明重啟成功
④ 回到web管理界面 --》點Status --》點Targets --》可以看到多了一台監 控目標
練習: 加上本機prometheus的監控
答: 在本機安裝node_exporter,也使用上面的方式監控起來。