PromQL (Prometheus Query Language) 是 Prometheus 自己开发的数据查询 DSL 语言,语言表现力非常丰富,内置函数很多,在日常数据可视化以及rule 告警中都会使用到它。
在页面 http://localhost:9090/graph 中,输入下面的查询语句,查看结果,例如:
prometheus_http_requests_total{code="200"}
 
查询结果类型
PromQL 查询结果主要有 3 种类型:
瞬时数据 (Instant vector): 包含一组时序,每个时序只有一个点,例如:prometheus_http_requests_total
区间数据 (Range vector): 包含一组时序,每个时序有多个点,例如:prometheus_http_requests_total[5m]
纯量数据 (Scalar): 纯量只有一个数字,没有时序,例如:count(prometheus_http_requests_total)
 
查询条件
Prometheus 存储的是时序数据,而它的时序是由名字和一组标签构成的,其实名字也可以写出标签的形式,例如 prometheus_http_requests_total 等价于 {name="http_requests_total"}。
一个简单的查询相当于是对各种标签的筛选,例如:
http_requests_total{code="200"} // 表示查询名字为 http_requests_total,code 为 "200" 的数据
 
查询条件支持正则匹配,例如:
prometheus_http_requests_total{code!="200"}  // 表示查询 code 不为 "200" 的数据
prometheus_http_requests_total{code=~"2.."} // 表示查询 code 为 "2xx" 的数据
prometheus_http_requests_total{code!~"2.."} // 表示查询 code 不为 "2xx" 的数据
 
内置函数
Prometheus 内置不少函数,方便查询以及数据格式化,例如将结果由浮点数转为整数的 floor 和 ceil,
floor(avg(prometheus_http_requests_total{code="200"}))
ceil(avgprometheus_(http_requests_total{code="200"}))
查看 prometheus_http_requests_total 5分钟内,平均每秒数据
rate(prometheus_http_requests_total[5m])
 
rate 与irate 区别:
irate和rate都会用于计算某个指标在一定时间间隔内的变化速率。但是它们的计算方法有所不同:irate取的是在指定时间范围内的最近两个数据点来算速率,而rate会取指定时间范围内所有数据点,算出一组速率,然后取平均值作为结果。
所以官网文档说:irate适合快速变化的计数器(counter),而rate适合缓慢变化的计数器(counter)。 

PromQL的更多相关文章

  1. Prometheus监控学习笔记之在 HTTP API 中使用 PromQL

    0x00 概述 Prometheus 当前稳定的 HTTP API 可以通过 /api/v1 访问. 0x01 API 响应格式 Prometheus API 使用了 JSON 格式的响应内容. 当 ...

  2. Prometheus监控学习笔记之PromQL操作符

    0x00 二元运算符 Prometheus 的查询语言支持基本的逻辑运算和算术运算.对于两个瞬时向量, 匹配行为可以被改变. 算术二元运算符 在 Prometheus 系统中支持下面的二元算术运算符: ...

  3. Prometheus监控学习笔记之初识PromQL

    0x00 概述 Prometheus 提供了一种功能表达式语言 PromQL,允许用户实时选择和汇聚时间序列数据.表达式的结果可以在浏览器中显示为图形,也可以显示为表格数据,或者由外部系统通过 HTT ...

  4. Prometheus PromQL 基础

    目录 时序 4 种类型 Counter Gauge Histogram Summary Histogram vs Summary 操作符 时序 4 种类型 Prometheus 时序数据分为 Coun ...

  5. Prometheus学习系列(七)之Prometheus PromQL说明

    前言 本文来自Prometheus官网手册1.2.3 和 Prometheus简介1.2.3 PromQL操作符 一.二元操作符 Prometheus的查询语言支持基本的逻辑运算和算术运算.对于两个瞬 ...

  6. Prometheus学习笔记(7)PromQL玩法入门

    目录 1.什么是PromQL??? 2.如何查询??? 1.什么是PromQL??? PromQL是Prometheus内置的数据查询语言,其提供对时间序列数据丰富的查询,聚合以及逻辑运算能力的支持. ...

  7. prometheus学习系列七: Prometheus promQL查询语言

    Prometheus promQL查询语言 Prometheus提供了一种名为PromQL (Prometheus查询语言)的函数式查询语言,允许用户实时选择和聚合时间序列数据.表达式的结果既可以显示 ...

  8. 【PromQL】prometheus查询语言

    常用查询: https://songjiayang.gitbooks.io/prometheus/content/exporter/nodeexporter_query.html group by 操 ...

  9. Prometheus的查询语法是PromQL基本语法

    PromQL(Prometheus Query Language)是 Prometheus 自己开发的表达式语言,语言表现力很丰富,内置函数也很多.使用它可以对时序数据进行筛选和聚合. 1- Prom ...

随机推荐

  1. Day9---Python的集合类

    集合类 1.生成办法: 可使用{.....}  或者set()生成集合,例如 a = {23,214,34,324,234,34} #这里的集合就是数学上的集合a = set('dsfasfsdf') ...

  2. Java arraylist重复使用问题

    arraylist同一个实例重复使用时,需要使用clear()及时清空,否则会在上次的结果后面添加项. List<Double> weightsList = new ArrayList&l ...

  3. jxl读取excel浮点数据时,小数点后三位截取问题

    今天导入Excel数据时,发现很多浮点数据被自动四舍五入只保留了三位,原来是jxl里对getContents()进行了封装,对数值型数据作了该处理.一般我们会对读取excel的一整套流程作为工具类,那 ...

  4. jsp常用代码

    1.头部 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&q ...

  5. JavaScript 正则表达式-严格匹配

    创建语法 var pattern = /test/;   或者  var pattern =  new RegExp("test"); 可配合使用以下三个标志 1) .i  可以使 ...

  6. shell命令结果重定向

  7. rabbiitmq非阻塞调用

    https://blog.csdn.net/panxianzhan/article/details/50755409 https://blog.csdn.net/u013946356/article/ ...

  8. Sass-字符串

    JavaScript支持css的两种字符串类型: 有引号字符串 (quoted strings),如 "Lucida Grande" .'http://sass-lang.com' ...

  9. center os 下redis安装以及基本使用

    解压并进入其目录 make cd src make install 默认情况,Redis不是在后台运行,我们需要把redis放在后台运行 vim /usr/local/redis/etc/redis. ...

  10. 为什么js的"关联数组"不能转成json字符串而对象可以?

    定义这么一个js的“关联数组”: var arr = new Array(); arr[; arr[; alert(JSON.stringify(arr)); 得到的结果如图: [] 一句话,你的 a ...