Prometheus + Grafana(一)Prometheus安裝部署


 

 

1.下載安裝

為您的平台下載最新版本的prometheus,然后將其解壓縮:

tar xvfz prometheus-*.tar.gz
cd prometheus-*

 官方guide

 

2.配置

根目錄下的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
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']

 

 

3.啟動

根目錄下執行以下命令:

./prometheus --config.file=prometheus.yml

 正常情況下,你可以看到如下輸出內容:

level=info ts=2018-10-23T14:55:14.499484Z caller=main.go:554 msg="Starting TSDB ..."
level=info ts=2018-10-23T14:55:14.499531Z caller=web.go:397 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-10-23T14:55:14.507999Z caller=main.go:564 msg="TSDB started"
level=info ts=2018-10-23T14:55:14.508068Z caller=main.go:624 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2018-10-23T14:55:14.509509Z caller=main.go:650 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2018-10-23T14:55:14.509537Z caller=main.go:523 msg="Server is ready to receive web requests."

 

 

4.使用表達試瀏覽器

讓我們看看prometheus收集到的一些關於自己的數據。要使用普羅米修斯的內置表達式瀏覽器,

請導航到 http://localhost:9090/graph 並在“graph”選項卡中選擇“Console”視圖。

 

您可以從 http://localhost:9090/metrics 收集,prometheus導出的關於其自身的一個度量稱為 promhttp_metric_handler_requests_total (prometheus服務器已服務的/metrics請求總數)。

繼續並將其輸入到表達式控制台中:

promhttp_metric_handler_requests_total

如果我們只對導致HTTP代碼200的請求感興趣,則可以使用此查詢檢索該信息:

promhttp_metric_handler_requests_total{code="200"}

 

要計算返回的時間序列數,可以編寫:

count(promhttp_metric_handler_requests_total)

有關表達式語言的更多信息,請參見: expression language documentation 

 

 

5.使用圖形界面

要繪制表達式,請導航到http://localhost:9090/graph並使用“graph”選項卡。
例如,輸入以下表達式以圖形化每秒在prometheus中發生的返回狀態代碼200的HTTP請求速率:

rate(promhttp_metric_handler_requests_total{code="200"}[1m])


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM