1. 非docker 環(huán)境下安裝
這是一個(gè)"hello-word" 風(fēng)格的教程;主要說明,如何安裝,配置并使用一個(gè)promethues的簡(jiǎn)單例子;你將在本地下載運(yùn)行promethues;配置它從他自己和一個(gè)小例子中獲取數(shù)據(jù),查詢,運(yùn)算和在圖表中使用獲取到的數(shù)據(jù)
下載并運(yùn)行promethues
下載最新版本的promethues,然后解壓并運(yùn)行
tar xvfz prometheus-*.tar.gz
cd prometheus-
在開始使用promethues之前,我們需要先配置一下
配置promethues 監(jiān)控他自己
promethues 通過已監(jiān)控目標(biāo)上的http端點(diǎn)(endpoint)來獲取目標(biāo)的數(shù)據(jù);由于promethues 將他自己以相同的方式暴露了出來,所以他可以獲取他自己的數(shù)據(jù)并監(jiān)控他自己的健康狀態(tài)
當(dāng)promethues只搜集他自己的數(shù)據(jù)的時(shí)候,不是一個(gè)很有用的實(shí)踐,但是這卻是一個(gè)很好的開始小例子;
將下面的配置保存名字為 promethues.yml
global:
scrape_interval: 15s # 默認(rèn)15秒獲取一下目標(biāo)數(shù)據(jù)
# 在與外部系統(tǒng)通信時(shí)(遠(yuǎn)程目標(biāo),報(bào)警管理) 添加這些label 到時(shí)間序列或者報(bào)警信息中
external_labels:
monitor: 'codelab-monitor'
# 配置包括一個(gè)準(zhǔn)確的端點(diǎn)去 scrape,這個(gè)是promethues自己的
scrape_configs:
# 這個(gè) job name 作為一個(gè)label `job=<job_name>` 添加到從配置中獲取的任何時(shí)間序列中
- job_name: 'prometheus'
# 覆蓋默認(rèn)配置
scrape_interval: 5s
static_configs:
# 目標(biāo)地址
- targets: ['localhost:9090']
開始promethues
切換到包含promethues二進(jìn)制文件的文件夾,使用新創(chuàng)建的配置文件啟動(dòng)
# 開始 Prometheus.
# 默認(rèn)的情況想,promethues存儲(chǔ)他的數(shù)據(jù)在 ./data 文件夾,可以使用 --storage.tsdb.path 改變文件夾地址
./prometheus --config.file=prometheus.yml
promethues 啟動(dòng)后可以訪問 localhost:9090 查看他自己的狀態(tài);幾秒鐘后他就開始通過http端點(diǎn)收集他自身的數(shù)據(jù);同時(shí)可以通過訪問 http://localhost:9090/metrics 來驗(yàn)證promethues是否獲取到自身的數(shù)據(jù);
使用表達(dá)式瀏覽器
在導(dǎo)航欄輸入 http://localhost:9090/graph 并選擇 console 欄;
你可以在 http://localhost:9090/metrics 中尋找到 prometheus_target_interval_length_seconds (目標(biāo)實(shí)際獲取數(shù)據(jù)之間的時(shí)間量),在 http://localhost:9090/graph 頁(yè)面上的 console 欄輸入 prometheus_target_interval_length_seconds
這里就會(huì)返回包含指標(biāo)名稱 prometheus_target_interval_length_seconds 的不同的時(shí)間序列;
quantile 解釋:
Prometheus中稱為quantile漆际,其實(shí)叫percentile更準(zhǔn)確屑迂。百分位數(shù)是指小于某個(gè)特定數(shù)值的采樣點(diǎn)達(dá)到一定的百分比拇颅。例如荧恍,假設(shè)0.9-quantile的值為120,意思就是所有的采樣值中拢军,小于120的采樣值的數(shù)量占總體采樣值的90%楞陷。相應(yīng)的,假設(shè)0.5-quantile的值為x茉唉,那么意思就是指小于x的采樣值占總體的50%固蛾,所以0.5-quantile也指中值(median)
如果我們想獲取采樣率90%的 數(shù)據(jù),可以輸入
prometheus_target_interval_length_seconds{quantile="0.9"}
如果想計(jì)算 返回時(shí)間序列的個(gè)數(shù) 可以輸入
count(prometheus_target_interval_length_seconds)
使用圖形界面
導(dǎo)航欄輸入 http://localhost:9090/graph 并選擇 graph 欄,就可以使用圖形界面了
輸入以下表達(dá)式:
rate(prometheus_tsdb_head_chunks_created_total[1m])