一些函數有默認的參數,例如:year(v=vector(time()) instant-vector)
。v是參數值,instant-vector是參數類型。vector(time())是默認值。git
abs(v instant-vector)
返回輸入向量的全部樣本的絕對值。github
absent(v instant-vector)
,若是賦值給它的向量具備樣本數據,則返回空向量;若是傳遞的瞬時向量參數沒有樣本數據,則返回不帶度量指標名稱且帶有標籤的樣本值爲1的結果正則表達式
當監控度量指標時,若是獲取到的樣本數據是空的, 使用absent方法對告警是很是有用的ubuntu
absent(nonexistent{job="myjob"}) # => key: value = {job="myjob"}: 1api
absent(nonexistent{job="myjob", instance=~".*"}) # => {job="myjob"} 1 so smart !ide
absent(sum(nonexistent{job="myjob"})) # => key:value {}: 0函數
ceil(v instant-vector)
是一個向上舍入爲最接近的整數。post
changes(v range-vector)
輸入一個範圍向量, 返回這個範圍向量內每一個樣本數據值變化的次數。spa
clamp_max(v instant-vector, max scalar)
函數,輸入一個瞬時向量和最大值,樣本數據值若大於max,則改成max,不然不變scala
clamp_min(v instant-vector)
函數,輸入一個瞬時向量和最大值,樣本數據值小於min,則改成min。不然不變
count_scalar(v instant-vector)
函數, 輸入一個瞬時向量,返回key:value="scalar": 樣本個數。而count()
函數,輸入一個瞬時向量,返回key:value=向量:樣本個數,其中結果中的向量容許經過by
條件分組。
day_of_month(v=vector(time()) instant-vector)
函數,返回被給定UTC時間所在月的第幾天。返回值範圍:1~31。
day_of_week(v=vector(time()) instant-vector)
函數,返回被給定UTC時間所在周的第幾天。返回值範圍:0~6. 0表示星期天。
days_in_month(v=vector(time()) instant-vector)
函數,返回當月一共有多少天。返回值範圍:28~31.
delta(v range-vector)
函數,計算一個範圍向量v的第一個元素和最後一個元素之間的差值。返回值:key:value=度量指標:差值
下面這個表達式例子,返回過去兩小時的CPU溫度差:
delta(cpu_temp_celsius{host="zeus"}[2h])
delta
函數返回值類型只能是gauges。
deriv(v range-vector)
函數,計算一個範圍向量v中各個時間序列二階導數,使用簡單線性迴歸
deriv
二階導數返回值類型只能是gauges。
drop_common_labels(instant-vector)
函數,輸入一個瞬時向量,返回值是key:value=度量指標:樣本值,其中度量指標是去掉了具備相同標籤。 例如:http_requests_total{code="200", host="127.0.0.1:9090", method="get"} : 4, http_requests_total{code="200", host="127.0.0.1:9090", method="post"} : 5, 返回值: http_requests_total{method="get"} : 4, http_requests_total{code="200", method="post"} : 5
exp(v instant-vector)
函數,輸入一個瞬時向量, 返回各個樣本值的e指數值,即爲e^N次方。特殊狀況以下所示:
Exp(+inf) = +Inf Exp(NaN) = NaN
floor(v instant-vector)
函數,與ceil()
函數相反。 4.3 爲 4 。
histogram_quatile(φ float, b instant-vector)
函數計算b向量的φ-直方圖 (0 ≤ φ ≤ 1) 。參考中文文獻[https://www.howtoing.com/how-to-query-prometheus-on-ubuntu-14-04-part-2/]
holt_winters(v range-vector, sf scalar, tf scalar)
函數基於範圍向量v,生成事件序列數據平滑值。平滑因子sf
越低, 對老數據越重要。趨勢因子tf
越高,越多的數據趨勢應該被重視。0< sf, tf <=1。 holt_winters
僅用於gauges
hour(v=vector(time()) instant-vector)
函數返回被給定UTC時間的當前第幾個小時,時間範圍:0~23。
idelta(v range-vector)
函數,輸入一個範圍向量,返回key: value = 度量指標: 每最後兩個樣本值差值。
increase(v range-vector)
函數, 輸入一個範圍向量,返回:key:value = 度量指標:last值-first值,自動調整單調性,如:服務實例重啓,則計數器重置。與delta()
不一樣之處在於delta是求差值,而increase返回最後一個減第一個值,可爲正爲負。
下面的表達式例子,返回過去5分鐘,連續兩個時間序列數據樣本值的http請求增長值。
increase(http_requests_total{job="api-server"}[5m])
increase
的返回值類型只能是counters,主要做用是增長圖表和數據的可讀性,使用rate
記錄規則的使用率,以便持續跟蹤數據樣本值的變化。
irate(v range-vector)
函數, 輸入:範圍向量,輸出:key: value = 度量指標: (last值-last前一個值)/時間戳差值。它是基於最後兩個數據點,自動調整單調性, 如:服務實例重啓,則計數器重置。
下面表達式針對範圍向量中的每一個時間序列數據,返回兩個最新數據點過去5分鐘的HTTP請求速率。
irate(http_requests_total{job="api-server"}[5m])
irate
只能用於繪製快速移動的計數器。由於速率的簡單更改能夠重置FOR子句,利用警報和緩慢移動的計數器,徹底由罕見的尖峯組成的圖形很難閱讀。
對於v中的每一個時間序列,label_replace(v instant-vector, dst_label string, replacement string, src_label string, regex string)
將正則表達式與標籤值src_label匹配。若是匹配,則返回時間序列,標籤值dst_label被替換的擴展替換。$1替換爲第一個匹配子組,$2替換爲第二個等。若是正則表達式不匹配,則時間序列不會更改。
另外一種更容易的理解是:label_replace
函數,輸入:瞬時向量,輸出:key: value = 度量指標: 值(要替換的內容:首先,針對src_label標籤,對該標籤值進行regex正則表達式匹配。若是不能匹配的度量指標,則不發生任何改變;不然,若是匹配,則把dst_label標籤的標籤紙替換爲replacement 下面這個例子返回一個向量值a帶有foo
標籤:label_replace(up{job="api-server", serice="a:c"}, "foo", "$1", "service", "(.*):.*")
ln(v instance-vector)
計算瞬時向量v中全部樣本數據的天然對數。特殊例子:
ln(+Inf) = +Inf ln(0) = -Inf ln(x<0) = NaN ln(NaN) = NaN
log2(v instant-vector)
函數計算瞬時向量v中全部樣本數據的二進制對數。
log10(v instant-vector)
函數計算瞬時向量v中全部樣本數據的10進制對數。至關於ln()
minute(v=vector(time()) instant-vector)
函數返回給定UTC時間當前小時的第多少分鐘。結果範圍:0~59。
month(v=vector(time()) instant-vector)
函數返回給定UTC時間當前屬於第幾個月,結果範圍:0~12。
predict_linear(v range-vector, t scalar)
預測函數,輸入:範圍向量和從如今起t秒後,輸出:不帶有度量指標,只有標籤列表的結果值。
例如:predict_linear(http_requests_total{code="200",instance="120.77.65.193:9090",job="prometheus",method="get"}[5m], 5) 結果: {code="200",handler="query_range",instance="120.77.65.193:9090",job="prometheus",method="get"} 1 {code="200",handler="prometheus",instance="120.77.65.193:9090",job="prometheus",method="get"} 4283.449995397104 {code="200",handler="static",instance="120.77.65.193:9090",job="prometheus",method="get"} 22.99999999999999 {code="200",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 130.90381188596754 {code="200",handler="graph",instance="120.77.65.193:9090",job="prometheus",method="get"} 2 {code="200",handler="label_values",instance="120.77.65.193:9090",job="prometheus",method="get"} 2
rate(v range-vector)
函數, 輸入:範圍向量,輸出:key: value = 不帶有度量指標,且只有標籤列表:(last值-first值)/時間差s
rate(http_requests_total[5m]) 結果: {code="200",handler="label_values",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="query_range",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="prometheus",instance="120.77.65.193:9090",job="prometheus",method="get"} 0.2 {code="200",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 0.003389830508474576 {code="422",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="static",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="graph",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="400",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 0
rate()
函數返回值類型只能用counters, 當用圖表顯示增加緩慢的樣本數據時,這個函數是很是合適的。
注意:當rate函數和聚合方式聯合使用時,通常先使用rate函數,再使用聚合操做, 不然,當服務實例重啓後,rate沒法檢測到counter重置。
resets()
函數, 輸入:一個範圍向量,輸出:key-value=沒有度量指標,且有標籤列表[在這個範圍向量中每一個度量指標被重置的次數]。在兩個連續樣本數據值降低,也能夠理解爲counter被重置。 示例:
resets(http_requests_total[5m]) 結果: {code="200",handler="label_values",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="query_range",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="prometheus",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="422",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="static",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="200",handler="graph",instance="120.77.65.193:9090",job="prometheus",method="get"} 0 {code="400",handler="query",instance="120.77.65.193:9090",job="prometheus",method="get"} 0
resets只能和counters一塊兒使用。
round(v instant-vector, to_nearest 1= scalar)
函數,與ceil
和floor
函數相似,輸入:瞬時向量,輸出:指定整數級的四捨五入值, 若是不指定,則是1之內的四捨五入。
scalar(v instant-vector)
函數, 輸入:瞬時向量,輸出:key: value = "scalar", 樣本值[若是度量指標樣本數量大於1或者等於0, 則樣本值爲NaN, 不然,樣本值自己]
sort(v instant-vector)
函數,輸入:瞬時向量,輸出:key: value = 度量指標:樣本值[升序排列]
sort(v instant-vector
函數,輸入:瞬時向量,輸出:key: value = 度量指標:樣本值[降序排列]
sqrt(v instant-vector)
函數,輸入:瞬時向量,輸出:key: value = 度量指標: 樣本值的平方根
time()
函數,返回從1970-01-01到如今的秒數,注意:它不是直接返回當前時間,而是時間戳
vector(s scalar)
函數,返回:key: value= {}, 傳入參數值
year(v=vector(time()) instant-vector)
, 返回年份。
下面的函數列表容許傳入一個範圍向量,返回一個帶有聚合的瞬時向量:
avg_over_time(range-vector)
: 範圍向量內每一個度量指標的平均值。min_over_time(range-vector)
: 範圍向量內每一個度量指標的最小值。max_over_time(range-vector)
: 範圍向量內每一個度量指標的最大值。sum_over_time(range-vector)
: 範圍向量內每一個度量指標的求和值。count_over_time(range-vector)
: 範圍向量內每一個度量指標的樣本數據個數。quantile_over_time(scalar, range-vector)
: 範圍向量內每一個度量指標的樣本數據值分位數,φ-quantile (0 ≤ φ ≤ 1)stddev_over_time(range-vector)
: 範圍向量內每一個度量指標的整體標準誤差。摘取來自Github 權侵刪!摘取來自Github 權侵刪!摘取來自Github 權侵刪!摘取來自Github 權侵刪!摘取來自Github 權侵刪!摘取來自Github 權侵刪!摘取來自Github 權侵刪!