有些函数有默认参数,例如year(v=vector(time()) instant-vector)。这意味着有一个参数 v 是一个瞬时向量,如果没有提供,它将默认为表达式vector(time())的值。instant-vector 表示参数类型。
Prometheus 当前有 42 个内置函数。分别如下:
abs()absent()absent_over_time()ceil()changes()clamp()clamp_max()clamp_min()day_of_month()day_of_week()days_in_month()delta()deriv()exp()floor()histogram_quantile()holt_winters()hour()idelta()increase()irate()label_join()label_replace()ln()log2()log10()minute()month()predict_linear()rate()resets()round()scalar()sgn()sort()sort_desc()sqrt()time()timestamp()vector()year()<aggregation>_over_time()
复制代码
abs()
abs(v instant-vector) 返回输入向量,所有样本值都转换为其绝对值。
这个针对单个 Metric 没什么效果,或者说这个函数应该是用在两个 Metric 做差的时候,保证结果永远是正数。
absent()
absent(v instant-vector) 如果传递给它的向量具有任何元素,则返回空向量;如果传递给它的向量没有元素,则返回值为 1 的 1 元素向量。
这这个函数主要用在给定 Metric 名称和 Label 组合不存在时间序列时发出警报或者在页面上展示。
# 这里提供的向量有样本数据absent(http_requests_total{method="get"}) => no dataabsent(sum(http_requests_total{method="get"})) => no data
# 由于不存在 Metric nonexistent,所以返回不带 Metric 名称且带有 label 的时间序列,且样本值为1absent(nonexistent{job="myjob"}) => {job="myjob"} 1# 正则匹配的 instance 不作为返回 labels 中的一部分absent(nonexistent{job="myjob",instance=~".*"}) => {job="myjob"} 1
# sum 函数返回的时间序列不带有 label,且没有样本数据absent(sum(nonexistent{job="myjob"})) => {} 1# 这个时候即使使用 by ,针对 sum 这些聚合函数也不会返回 label。absent(sum(nonexistent{job="myjob"}) by (job)) => {} 1
复制代码
absent_over_time()
absent_over_time() 和 absent() 非常类似。
absent_over_time(v range-vector) 如果传递给它的范围向量有任何元素,则返回一个空向量,如果传递给它的范围向量没有元素,则返回一个值为 1 的 1 元素向量。
这对于在给定的指标名称和标签组合在一定时间内不存在时间序列时发出警报非常有用。
absent_over_time(nonexistent{job="myjob"}[1h]) => {job="myjob"}
absent_over_time(nonexistent{job="myjob",instance=~".*"}[1h]) => {job="myjob"}
absent_over_time(sum(nonexistent{job="myjob"})[1h:]) => {}
复制代码
ceil()
ceil(v instant-vector) 将 v 中所有元素的样本值向上四舍五入到最接近的整数。例如:
node_load5{instance="192.168.1.75:9100"} # 结果为 2.79ceil(node_load5{instance="192.168.1.75:9100"}) # 结果为 3
复制代码
评论 (1 条评论)