1. 程式人生 > >Prometheus安裝和基本配置

Prometheus安裝和基本配置

Prometheus的主要特點
Prometheus 屬於一站式監控告警平臺,依賴少,功能齊全。
Prometheus 支援對雲的或容器的監控,其他系統主要對主機監控。
Prometheus 資料查詢語句表現力更強大,內建更強大的統計函式。
Prometheus 在資料儲存擴充套件性以及永續性上沒有 InfluxDB,OpenTSDB,Sensu 好。

Prometheus的核心元件
Prometheus Server, 主要用於抓取資料和儲存時序資料,另外還提供查詢和 Alert Rule 配置管理。
client libraries,用於對接 Prometheus Server, 可以查詢和上報資料。
push gateway ,用於批量,短期的監控資料的彙總節點,主要用於業務資料彙報等。
各種彙報資料的 exporters ,例如彙報機器資料的 node_exporter, 彙報 MongoDB 資訊的 MongoDB exporter 等等。
用於告警通知管理的 alertmanager 。

Prometheus的架構圖

 

從這個架構圖,也可以看出 Prometheus 的主要模組包含, Server, Exporters, Pushgateway, PromQL, Alertmanager, WebUI 等。

它大致使用邏輯是這樣:

Prometheus server 定期從靜態配置的 targets 或者服務發現的 targets 拉取資料。
當新拉取的資料大於配置記憶體快取區的時候,Prometheus 會將資料持久化到磁碟(如果使用 remote storage 將持久化到雲端)。
Prometheus 可以配置 rules,然後定時查詢資料,當條件觸發的時候,會將 alert 推送到配置的 Alertmanager。
Alertmanager 收到警告的時候,可以根據配置,聚合,去重,降噪,最後傳送警告。
可以使用 API, Prometheus Console 或者 Grafana 查詢和聚合資料。
 
Prometheus的安裝

下載 prometheus-2.0.0.linux-amd64.tar.gz
http://download.csdn.net/download/fly910905/10130519
tar -zxvf prometheus-2.0.0.linux-amd64.tar.gz
cd prometheus-2.0.0.linux-amd64.tar.gz
./prometheus

Prometheus的配置
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# 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'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'mydemo'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
metrics_path: '/prometheus'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.60.207:8088']
最關鍵的配置就是targets,就是web應用的ip和埠

Prometheus的啟動
http://localhost:9090/targets
---------------------
作者:琦彥
來源:CSDN
原文:https://blog.csdn.net/fly910905/article/details/78618534
版權宣告:本文為博主原創文章,轉載請附上博文連結!