函数列表


一些函数有默认的参数,例如:year(v=vector(time()) instant-vector)。v是参数值,instant-vector是参数类型。vector(time())是默认值。

abs()

abs(v instant-vector)返回输入向量的所有样本的绝对值。

absent()

absent(v instant-vector),如果赋值给它的向量具有样本数据,则返回空向量;如果传递的瞬时向量参数没有样本数据,则返回不带度量指标名称且带有标签的样本值为1的结果

当监控度量指标时,如果获取到的样本数据是空的, 使用absent方法对告警是非常有用的

absent(nonexistent{job="myjob"}) # => key: value = {job="myjob"}: 1

absent(nonexistent{job="myjob", instance=~".*"}) # => {job="myjob"} 1 so smart !

absent(sum(nonexistent{job="myjob"})) # => key:value {}: 0

ceil()

ceil(v instant-vector) 是一个向上舍入为最接近的整数。

changes()

changes(v range-vector) 输入一个范围向量, 返回这个范围向量内每个样本数据值变化的次数。

clamp_max()

clamp_max(v instant-vector, max scalar)函数,输入一个瞬时向量和最大值,样本数据值若大于max,则改为max,否则不变

clamp_min()

clamp_min(v instant-vector)函数,输入一个瞬时向量和最大值,样本数据值小于min,则改为min。否则不变

count_saclar()

count_scalar(v instant-vector) 函数, 输入一个瞬时向量,返回key:value="scalar": 样本个数。而count()函数,输入一个瞬时向量,返回key:value=向量:样本个数,其中结果中的向量允许通过by条件分组。

day_of_month()

day_of_month(v=vector(time()) instant-vector)函数,返回被给定UTC时间所在月的第几天。返回值范围:1~31。

day_of_week()

day_of_week(v=vector(time()) instant-vector)函数,返回被给定UTC时间所在周的第几天。返回值范围:0~6. 0表示星期天。

days_in_month()

days_in_month(v=vector(time()) instant-vector)函数,返回当月一共有多少天。返回值范围:28~31.

delta()

delta(v range-vector)函数,计算一个范围向量v的第一个元素和最后一个元素之间的差值。返回值:key:value=度量指标:差值

下面这个表达式例子,返回过去两小时的CPU温度差:

delta(cpu_temp_celsius{host="zeus"}[2h])

delta函数返回值类型只能是gauges。

deriv()

deriv(v range-vector)函数,计算一个范围向量v中各个时间序列二阶导数,使用简单线性回归

deriv二阶导数返回值类型只能是gauges。

drop_common_labels()

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()

exp(v instant-vector)函数,输入一个瞬时向量, 返回各个样本值的e指数值,即为e^N次方。特殊情况如下所示:

Exp(+inf) = +Inf Exp(NaN) = NaN

floor()

floor(v instant-vector)函数,与ceil()函数相反。 4.3 为 4 。

histogram_quantile()

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()

holt_winters(v range-vector, sf scalar, tf scalar)函数基于范围向量v,生成事件序列数据平滑值。平滑因子sf越低, 对老数据越重要。趋势因子tf越高,越多的数据趋势应该被重视。0< sf, tf <=1。 holt_winters仅用于gauges

hour()

hour(v=vector(time()) instant-vector)函数返回被给定UTC时间的当前第几个小时,时间范围:0~23。

idelta()

idelta(v range-vector)函数,输入一个范围向量,返回key: value = 度量指标: 每最后两个样本值差值。

increase()

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

irate(v range-vector)函数, 输入:范围向量,输出:key: value = 度量指标: (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 = 度量指标: 值(要替换的内容:首先,针对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"} 2

rate()

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()

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()

round(v instant-vector, to_nearest 1= scalar)函数,与ceilfloor函数类似,输入:瞬时向量,输出:指定整数级的四舍五入值, 如果不指定,则是1以内的四舍五入。

scalar()

scalar(v instant-vector)函数, 输入:瞬时向量,输出:key: value = "scalar", 样本值[如果度量指标样本数量大于1或者等于0, 则样本值为NaN, 否则,样本值本身]

sort()

sort(v instant-vector)函数,输入:瞬时向量,输出:key: value = 度量指标:样本值[升序排列]

sort_desc()

sort(v instant-vector函数,输入:瞬时向量,输出:key: value = 度量指标:样本值[降序排列]

sqrt()

sqrt(v instant-vector)函数,输入:瞬时向量,输出:key: value = 度量指标: 样本值的平方根

time()

time()函数,返回从1970-01-01到现在的秒数,注意:它不是直接返回当前时间,而是时间戳

vector()

vector(s scalar)函数,返回:key: value= {}, 传入参数值

year()

year(v=vector(time()) instant-vector), 返回年份。

_over_time()

下面的函数列表允许传入一个范围向量,返回一个带有聚合的瞬时向量:

  • 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): 范围向量内每个度量指标的总体标准偏差。
  • `stdvar_over_time(range-vector): 范围向量内每个度量指标的总体标准方差。

摘取来自Github 权侵删!摘取来自Github 权侵删!摘取来自Github 权侵删!摘取来自Github 权侵删!摘取来自Github 权侵删!摘取来自Github 权侵删!摘取来自Github 权侵删!

Prometheus 函数的更多相关文章

  1. prometheus函数介绍

    一 函数介绍 gauge类型的数据  属于随机变化数值,并不像counter那样 是 持续增长 1 increase() increase 函数 在promethes中,是⽤来 针对Counter 这 ...

  2. Prometheus监控学习记录

    官方文档 Prometheus基础文档 从零开始:Prometheus 进阶之路:Prometheus —— 技巧篇 进阶之路:Prometheus —— 理解篇 prometheus的数据类型介绍 ...

  3. promethues常用的函数

    prometheus函数常用 时数据 (Instant vector): 包含一组时序,每个时序只有一个点,例如:http_requests_total区间数据 (Range vector): 包含一 ...

  4. 创建Grafana监控视图

    前言 Grafana允许查询,可视化,警报和了解指标,无论它们存储在哪里. 可视化:具有多种选项的快速灵活的客户端图.面板插件提供了许多不同的方式来可视化指标和日志. 动态仪表盘:使用模板变量创建动态 ...

  5. Prometheus监控学习笔记之PromQL 内置函数

    概述 Prometheus 提供了其它大量的内置函数,可以对时序数据进行丰富的处理.某些函数有默认的参数,例如:year(v=vector(time()) instant-vector).其中参数 v ...

  6. prometheus告警函数

    PromQL基础     http_request_total{} 瞬时向量表达式,选择当前最新的数据 http_request_total{}[5m] 区间向量表达式,选择以当前时间为基准,5分钟内 ...

  7. Prometheus 到底 NB 在哪里?- 每天5分钟玩转 Docker 容器技术(84)

    本节讨论 Prometheus 的核心,多维数据模型.我们先来看一个例子. 比如要监控容器 webapp1 的内存使用情况,最传统和典型的方法是定义一个指标 container_memory_usag ...

  8. 使用 Prometheus + Grafana 对 Kubernetes 进行性能监控的实践

    1 什么是 Kubernetes? Kubernetes 是 Google 开源的容器集群管理系统,其管理操作包括部署,调度和节点集群间扩展等. 如下图所示为目前 Kubernetes 的架构图,由 ...

  9. prometheus client_golang使用

    序言 Prometheus是一个开源的监控系统,拥有许多Advanced Feature,他会定期用HTTP协议来pull所监控系统状态进行数据收集,在加上timestamp等数据组织成time se ...

随机推荐

  1. domino server端的Notes.ini详解

    Web代理监控与调式问题     Web代理在服务器的执行优先级是最高的,由Web代理引发的服务器宕机现象很多,但是我们很难监控Web代理的运行.通过对notes.ini的研究可以通过如下途径进行处理 ...

  2. 重写$.ajax方法

    /*重写Jquery中的ajax 封装壳*/ $(function () { (function ($) { //首先备份下jquery的ajax方法 var _ajax = $.ajax; //重写 ...

  3. 浅谈常用的几种web攻击方式

    一.Dos攻击(Denial of Service attack) 是一种针对服务器的能够让服务器呈现静止状态的攻击方式.有时候也加服务停止攻击或拒绝服务攻击.其原理就是发送大量的合法请求到服务器,服 ...

  4. C语言(C++语言)中##(两个井号)和#(一个井号)用法[转]

    文章来源:http://blog.csdn.net/starboybenben/article/details/49803315 C语言(C++语言)中的宏(Macro)属于编译器预处理的范畴,属于编 ...

  5. Authentication 方案优化探索(JWT, Session, Refresh Token, etc.)

    转载自:http://www.jianshu.com/p/5ac8a0e1e5a8

  6. RxSwift之路 2#如何开始

    RxSwift之路 2#如何开始 第一步当然是把项目clone到本地,github地址:https://github.com/ReactiveX/RxSwift. 官方文档 学习的第一手资源当然是项目 ...

  7. linux每日命令(14):less命令

    less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...

  8. 按enter键触发登录事件

    $(document).keydown(function(event){ if(event.keyCode==13){ $(".submit").click(); } });

  9. 【转】SAP BW 顾问靠手 — SAP中的例程

    什么是例程(Routine)? 例程就是我们可以自己定义的程序代码.通过程序代码来完成我们的需求,因为业务是千变万化,如果想让产品能跟随上业务的脚步,就必须要有非常灵活的功能来补充.大家都知道软件产品 ...

  10. android设置字符串到剪贴板

    android2.1之后版本 其一:(已运行成功) ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOA ...