溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Prometheus-2.15.0部署

發(fā)布時(shí)間:2020-06-01 06:14:03 來(lái)源:網(wǎng)絡(luò) 閱讀:447 作者:BonnieJason 欄目:系統(tǒng)運(yùn)維

一、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 具有以下特性

  1. 多維的數(shù)據(jù)模型(基于時(shí)間序列的 Key/Value 鍵值對(duì))
  2. 靈活的查詢和聚合語(yǔ)言 PromQL
  3. 提供本地存儲(chǔ)和分布式存儲(chǔ)
  4. 通過(guò)基于 HTTP 的 Pull 模型采集時(shí)間序列數(shù)據(jù)
  5. 可利用 Pushgateway(Prometheus 的可選中間件)實(shí)現(xiàn) Push 模式
  6. 可通過(guò)動(dòng)態(tài)服務(wù)發(fā)現(xiàn)或靜態(tài)配置發(fā)現(xiàn)目標(biāo)機(jī)器
  7. 支持多種圖表和數(shù)據(jù)大盤

三、架構(gòu)
prometheus是一個(gè)用Go編寫的時(shí)序數(shù)據(jù)庫(kù),可以支持多種語(yǔ)言客戶端
Prometheus-2.15.0部署


四、模塊介紹

  • 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)用即可,如 MySQLMongoDB 等,可以參考這里。

  • Push Gateway
    Prometheus 采集指標(biāo)的方式主要有兩種,一種是服務(wù)端暴露接口(Exporter),由 Prometheus 主動(dòng)去抓取指標(biāo),稱為 pull 模式。另一種是服務(wù)端主動(dòng)上報(bào),服務(wù)端將指標(biāo)主動(dòng)上報(bào)至 Push Gateway,Prometheus 再?gòu)?Push Gateway 中獲取,稱為 push 模式。而 Push Gateway 就是 push 模式中重要的中介角色,用于暫存服務(wù)端上報(bào)的指標(biāo),等待 Prometheus 收集。

為什么要有兩種模式呢?我們來(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)警的分組、聚合、抑制、沉默等功能。

  • Web UI/Grafana
    Prometheus 提供了一個(gè)簡(jiǎn)單的 web UI 界面,用于查詢數(shù)據(jù),查看告警、配置等,官方推薦使用另一個(gè)開(kāi)源項(xiàng)目 grafana 來(lái)做指標(biā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

Prometheus-2.15.0部署
Prometheus-2.15.0部署


六、配置說(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-2.15.0部署

參考鏈接:prometheus安裝

向AI問(wèn)一下細(xì)節(jié)
推薦閱讀:
  1. sybase部署
  2. Django部署

免責(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)容。

AI