Prometheus

監控告警:node

Prometheus + grafana +alertmanagerredis

Prometheus  介紹:bash

更多請參考官方文檔: https://prometheus.io/docs/分佈式

什麼是prometheus :ide

Prometheus 是一個開源的監控系統,和告警工具,被多家公司所採納監控。函數

特徵:工具

 1 . 是一個多維數據模型,具備由度量名稱/鍵值對標誌的時間序列數據。lua

 2.  是一種靈活的查詢語言url

 3.  單個服務節點是自制的, 不依賴分佈式存儲spa

 4.  時間序列經過http 的拉取模式

 5 . 推送時間序列經過中間網關支持

 6 . 經過服務發現和配置來來發現目標

 7. 多種模式的圖形和儀表盤支持

Prometheus 構成:

 

 

    解釋: 

     主要是用來抓取和存儲時間序列,分爲Prometheus Server 主要分爲三個組成部分, Retrieval  主要是用來服務發現配置的, Storge 主要用來存儲數據,PromQL 高級查詢語句:抓取方式:

    主要是經過Jobs/Exporters  和中間網關拉取 metrics,並推送告警規則 alertmanager , 總的來講是, Prometheus直接或經過中介推送網關從短時間工做中提取儀器化工做的指標。它在本地存儲全部抓取的樣本,並對這些數據運行規則,以聚合和記錄現有數據的新時間序列或生成警報。Grafana或其餘API消費者可用於可視化收集的數據。 

     適用範圍;

       以機器爲中心的監控和高度動態的面向服務體系的監控,支持多維數據的收集 和查詢。prometheus可靠,可是不可是數據不會是百分一百的準確性的(好比按請求計費)

 

   Prometheus 安裝部署:

    下載Prometheus ,解壓:

1 tar xvfz prometheus-*.tar.gz 2 
3 cd prometheus-*

   配置Prometheus.yml

global: scrape_interval: 15s evaluation_interval: 15s rule_files: # - "first.rules" # - "second.rules" scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090']

  global :是全局配置, rule_files 是告警規則配置,也能夠適用正則, 第三部分是抓取配置(好比redis監控信息),

scrape_interval表示每隔多久抓取一次,
evaluation_interval 表示多久一次評估規則,--》 生成告警


*.rules 告警規則文件。

scrape_configs: 配置完成,咱們能夠經過:http:// localhost:9090 / metrics來抓取。

重啓Prometheus : Curl -X Post http://localhost:port//-//

http_requests_total{code="200"} 表達式 能夠查詢信息.(參考表達是語言文檔)

從官網下載 Exporter
tar xvfz node_exporter-*.tar.gz cd node_exporter-*

啓動
./node_exporter 

須要配置Job_Name:

- job_name: node static_configs: - targets: ['localhost:9100']

 

 重啓Prometheus ,就能夠在consule 看到監控指標了。



Prometheus 度量類型:

1 .counter
一個計數器是表明永遠只上升1個數值累計度量。計數器一般用於計數提供的請求數,完成的任務數,發生的錯誤數等。
2 .Gauge
儀表一般用於測量值,如溫度或當前的存儲器使用狀況,但也能夠上升和降低的「計數」,如正在運行的goroutines的數量。
3. histogram

   具備基本度量標準名稱的直方圖<basename>在刮取期間顯示多個時間序列:

 
 
  •   觀察桶的累計計數器,暴露爲 <basename>_bucket{le="<upper inclusive bound>"}
  • 總和的全部觀察值的,公開爲<basename>_sum
  • 計數已觀察到的事件的,公開爲<basename>_count(等同於<basename>_bucket{le="+Inf"}上文)
 
 

     使用該 histogram_quantile()函數 從直方圖或直方圖聚合中計算分位數。直方圖也適用於計算 Apdex分數在桶上操做時,請記住直方圖是 累積的有關直方圖使用狀況和摘要差別的詳細信息,請參閱 直方圖和摘  要


4. Summary

Similar to a histogram, a summary samples observations (usually things like request durations and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.

 
 

A summary with a base metric name of <basename> exposes multiple time series during a scrape:

 
 
  • streaming φ-quantiles (0 ≤ φ ≤ 1) of observed events, exposed as <basename>{quantile="<φ>"}
  • the total sum of all observed values, exposed as <basename>_sum
  • the count of events that have been observed, exposed as <basename>_count
 
 

See histograms and summaries for detailed explanations of φ-quantiles, summary usage, and differences to histograms.

相關文章
相關標籤/搜索