自然对数公式推导 高中数学对数函数知识点( 二 )


下面的表达式例子 , 返回过去5分钟 , 连续两个时间序列数据样本值的http请求增加值 。

increase(http_requests_total{job=”api-server”}[5m])
increase的返回值类型只能是counters , 主要作用是增加图表和数据的可读性 , 使用rate记录规则的使用率 , 以便持续跟踪数据样本值的变化 。
irateirate(v range-vector)函数, 输入:范围向量 , 输出:key: value = https://www.yf-zs.com/shuma/度量指标: (last值-last前一个值)/时间戳差值 。它是基于最后两个数据点 , 自动调整单调性 , 如:服务实例重启 , 则计数器重置 。
下面表达式针对范围向量中的每个时间序列数据 , 返回两个最新数据点过去5分钟的HTTP请求速率 。
irate(http_requests_total{job=”api-server”}[5m])
irate只能用于绘制快速移动的计数器 。因为速率的简单更改可以重置FOR子句 , 利用警报和缓慢移动的计数器 , 完全由罕见的尖峰组成的图形很难阅读 。
label_replace()对于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 = https://www.yf-zs.com/shuma/度量指标: 值(要替换的内容:首先 , 针对src_label标签 , 对该标签值进行regex正则表达式匹配 。如果不能匹配的度量指标 , 则不发生任何改变;否则 , 如果匹配 , 则把dst_label标签的标签纸替换为replacement 下面这个例子返回一个向量值a带有foo标签:label_replace(up{job=”api-server”, serice=”a:c”}, “foo”, “$1”, “service”, “(.*):.*”)
ln()ln(v instance-vector)计算瞬时向量v中所有样本数据的自然对数 。特殊例子:
ln(+Inf) = +Inf ln(0) = -Inf ln(x<0) = NaN ln(NaN) = NaN
log2()log2(v instant-vector)函数计算瞬时向量v中所有样本数据的二进制对数 。
log10()log10(v instant-vector)函数计算瞬时向量v中所有样本数据的10进制对数 。相当于ln()
minute()minute(v=vector(time()) instant-vector)函数返回给定UTC时间当前小时的第多少分钟 。结果范围:0~59 。
month()month(v=vector(time()) instant-vector)函数返回给定UTC时间当前属于第几个月 , 结果范围:0~12 。
predict_linear()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"} 2rate()rate(v range-vector)函数, 输入:范围向量 , 输出:key: value = https://www.yf-zs.com/shuma/不带有度量指标 , 且只有标签列表:(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"}0rate()函数返回值类型只能用counters ,  当用图表显示增长缓慢的样本数据时 , 这个函数是非常合适的 。

推荐阅读