您好,登錄后才能下訂單哦!
一、Prometheus介紹
Prometheus 是一套開(kāi)源的系統(tǒng)監(jiān)控和報(bào)警框架,靈感源自 Google 的 Borgmon 監(jiān)控系統(tǒng)。2012 年,SoundCloud 的 Google 前員工創(chuàng)造了 Prometheus,并作為社區(qū)開(kāi)源項(xiàng)目進(jìn)行開(kāi)發(fā)。2015 年,該項(xiàng)目正式發(fā)布。2016 年,Prometheus 加入云原生計(jì)算基金會(huì)(Cloud Native Computing Foundation),成為受歡迎度僅次于 Kubernetes 的項(xiàng)目。
二、Prometheus 具有以下特性
三、架構(gòu)
prometheus是一個(gè)用Go編寫的時(shí)序數(shù)據(jù)庫(kù),可以支持多種語(yǔ)言客戶端
四、模塊介紹
Prometheus Server
Prometheus Server 是監(jiān)控系統(tǒng)的服務(wù)端,服務(wù)端通過(guò)服務(wù)發(fā)現(xiàn)的方式,抓取被監(jiān)控服務(wù)的指標(biāo),或者通過(guò) pushgateway 的間接抓取,抓取到指標(biāo)數(shù)據(jù)后,通過(guò)特定的存儲(chǔ)引擎進(jìn)行存儲(chǔ),同時(shí)暴露一個(gè) HTTP 服務(wù),提供用 PromQL 來(lái)進(jìn)行數(shù)據(jù)查詢。注意,Prometheus 是定時(shí)采樣數(shù)據(jù),而不是全量數(shù)據(jù)。
Exporter
Prometheus 需要服務(wù)暴露 http 接口,如果服務(wù)本身沒(méi)有,我們不需要改造服務(wù),可以通過(guò) exporter 來(lái)間接獲取。Exporter 就充當(dāng)了 Prometheus 采集的目標(biāo),而由各個(gè) exporter 去直接獲取指標(biāo)。目前大多數(shù)的服務(wù)都有現(xiàn)成的 exporter,我們不需要重復(fù)造輪子,拿來(lái)用即可,如 MySQL,MongoDB 等,可以參考這里。
為什么要有兩種模式呢?我們來(lái)比較一下這兩種模式的特點(diǎn)。
1、Pull 模式:Prometheus 主動(dòng)抓取的方式,可以由 Prometheus 服務(wù)端控制抓取的頻率,簡(jiǎn)單清晰,控制權(quán)在 Prometheus 服務(wù)端。通過(guò)服務(wù)發(fā)現(xiàn)機(jī)制,可以自動(dòng)接入新服務(wù),去掉下線的服務(wù),無(wú)需任何人工干預(yù)。對(duì)于各種常見(jiàn)的服務(wù),官方或社區(qū)有大量 Exporter 來(lái)提供指標(biāo)采集接口,基本無(wú)需開(kāi)發(fā)。是官方推薦的方式。
2、Push 模式:由服務(wù)端主動(dòng)上報(bào)至 Push Gateway,采集最小粒度由服務(wù)端決定,等于 Push Gateway 充當(dāng)了中介的角色,收集各個(gè)服務(wù)主動(dòng)上報(bào)的指標(biāo),然后再由 Prometheus 來(lái)采集。但是這樣就存在了 Push Gateway 這個(gè)性能單點(diǎn),而且 Push Gateway 也要處理持久化問(wèn)題,不然宕機(jī)也會(huì)丟失部分?jǐn)?shù)據(jù)。同時(shí)需要服務(wù)端提供主動(dòng)上報(bào)的功能,可能涉及一些開(kāi)發(fā)改動(dòng)。不是首選的方式,但是在一些場(chǎng)景下很適用。例如,一些臨時(shí)性的任務(wù),存在時(shí)間可能非常短,如果采用 Pull 模式,可能抓取不到數(shù)據(jù)。
Alert Manager
Alert Manager 是 Prometheus 的報(bào)警組件,當(dāng) Prometheus 服務(wù)端發(fā)現(xiàn)報(bào)警時(shí),推送 alert 到 Alert Manager,再由 Alert Manager 發(fā)送到通知端,如 Email,Slack,微信,釘釘?shù)?。Alert Manager 根據(jù)相關(guān)規(guī)則提供了報(bào)警的分組、聚合、抑制、沉默等功能。
五、下載
下載地址:https://prometheus.io/download/
下載server
wget -c https://github.com/prometheus/prometheus/releases/download/v2.15.0/prometheus-2.15.0.linux-amd64.tar.gz
下載node
wget -c https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
六、配置說(shuō)明
配置文件:prometheus.yml
# 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 #報(bào)警監(jiān)控配置
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"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
說(shuō)明:
global:全局配置,其中scrape_interval表示抓取一次數(shù)據(jù)的間隔時(shí)間,evaluationinterval:表示進(jìn)行告警規(guī)則檢測(cè)的間隔時(shí)間;
alerting:告警管理器(Alertmanager)的配置,需要安裝Alertmanager;
rulefiles:告警規(guī)則有哪些;
scrapeconfigs:抓取監(jiān)控信息的目標(biāo)。一個(gè)job_name就是一個(gè)目標(biāo),其targets就是采集信息的IP和端口。這里默認(rèn)監(jiān)控了Prometheus自己,可以通過(guò)修改這里來(lái)修改Prometheus的監(jiān)控端口。Prometheus的每個(gè)exporter都會(huì)是一個(gè)目標(biāo),它們可以上報(bào)不同的監(jiān)控信息,比如機(jī)器狀態(tài),或者mysql性能等等,不同語(yǔ)言sdk也會(huì)是一個(gè)目標(biāo),它們會(huì)上報(bào)你自定義的業(yè)務(wù)監(jiān)控信息。
七、部署
部署流程:
1、在監(jiān)控服務(wù)器上安裝prometheus
2、在被監(jiān)控環(huán)境上安裝exporte
1、server啟動(dòng)方法:./prometheus --config.file=/data/prometheus-2.15.0.linux-amd64/prometheus.yml
2、node啟動(dòng)方法:nohup ./node_exporter &
3、將應(yīng)用添加到系統(tǒng)服務(wù)
vim /etc/systemd/system/prometheus.service
[unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
[Service]
ExecStart=/data/prometheus/prometheus \
--config.file=/data/prometheus/prometheus.yml \
--web.listen-address=:9090
##此處文件路徑請(qǐng)對(duì)照安裝目錄
[Install]
WantedBy=multi-user.target
然后就可以通過(guò)systemctl start|stop|status|enable promethues.service進(jìn)行管理了
八、訪問(wèn)
http://127.0.0.1:9090
參考鏈接:prometheus安裝
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。