SkyWalking内置MQE语法

此文档出自SkyWalking官方git https://github.com/apache/skywalking
docs/en/api/metrics-query-expression.md

Metrics Query Expression(MQE) Syntax

MQE is a string that consists of one or more expressions. Each expression could be a combination of one or more operations.
The expression allows users to do simple query-stage calculation through V3 APIs.

Expression = <Operation> Expression1 <Operation> Expression2 <Operation> Expression3 ...

The following document lists the operations supported by MQE.

Metrics Expression

Metrics Expression will return a collection of time-series values.

Common Value Metrics

Expression:

<metric_name>

For example:
If we want to query the service_sla metric, we can use the following expression:

service_sla

Result Type

The ExpressionResultType of the expression is TIME_SERIES_VALUES.

Labeled Value Metrics

For now, we only have a single anonymous label with multi label values in a labeled metric.
To be able to use it in expressions, define _ as the anonymous label name (key).

Expression:

<metric_name>{_='<label_value_1>,...'}

{_='<label_value_1>,...'} is the selected label value of the metric. If is not specified, all label values of the metric will be selected.

For example:
If we want to query the service_percentile metric with the label values 0,1,2,3,4, we can use the following expression:

service_percentile{_='0,1,2,3,4'}

If we want to rename the label values to P50,P75,P90,P95,P99, see Relabel Operation.

Result Type

The ExpressionResultType of the expression is TIME_SERIES_VALUES and with labels.

Binary Operation

The Binary Operation is an operation that takes two expressions and performs a calculation on their results.
The following table lists the binary operations supported by MQE.

Expression:

Expression1 <Binary-Operator> Expression2
OperatorDefinition
+addition
-subtraction
*multiplication
/division
%modulo

For example:
If we want to transform the service_sla metric value to percent, we can use the following expression:

service_sla / 100

Result Type

For the result type of the expression, please refer to the following table.

Binary Operation Rules

The following table lists if the different result types of the input expressions could do this operation and the result type after the operation.
The expression could be on the left or right side of the operator.
Note: If the expressions on both sides of the operator are the TIME_SERIES_VALUES with labels, they should have the same labels for calculation.

ExpressionExpressionYes/NoExpressionResultType
SINGLE_VALUESINGLE_VALUEYesSINGLE_VALUE
SINGLE_VALUETIME_SERIES_VALUESYesTIME_SERIES_VALUES
SINGLE_VALUESORTED_LIST/RECORD_LISTYesSORTED_LIST/RECORD_LIST
TIME_SERIES_VALUESTIME_SERIES_VALUESYesTIME_SERIES_VALUES
TIME_SERIES_VALUESSORTED_LIST/RECORD_LISTno
SORTED_LIST/RECORD_LISTSORTED_LIST/RECORD_LISTno

Compare Operation

Compare Operation takes two expressions and compares their results.
The following table lists the compare operations supported by MQE.

Expression:

Expression1 <Compare-Operator> Expression2
OperatorDefinition
>greater than
>=greater than or equal
<less than
<=less than or equal
==equal
!=not equal

The result of the compare operation is an int value:

  • 1: true
  • 0: false

For example:
Compare the service_resp_time metric value if greater than 3000, if the service_resp_time result is:

{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": []},"values": [{"id": "1691658000000", "value": "2500", "traceID": null}, {"id": "1691661600000", "value": 3500, "traceID": null}]}]}}
}

we can use the following expression:

service_resp_time > 3000

and get result:

{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": []},"values": [{"id": "1691658000000", "value": "0", "traceID": null}, {"id": "1691661600000", "value": 1, "traceID": null}]}]}}
}

Compare Operation Rules and Result Type

Same as the Binary Operation Rules.

Aggregation Operation

Aggregation Operation takes an expression and performs aggregate calculations on its results.

Expression:

<Aggregation-Operator>(Expression)
OperatorDefinitionExpressionResultType
avgaverage the resultSINGLE_VALUE
countcount number of the resultSINGLE_VALUE
latestselect the latest non-null value from the resultSINGLE_VALUE
sumsum the resultSINGLE_VALUE
maxselect maximum from the resultSINGLE_VALUE
minselect minimum from the resultSINGLE_VALUE

For example:
If we want to query the average value of the service_cpm metric, we can use the following expression:

avg(service_cpm)

Result Type

The different operators could impact the ExpressionResultType, please refer to the above table.

Mathematical Operation

Mathematical Operation takes an expression and performs mathematical calculations on its results.

Expression:

<Mathematical-Operator>(Expression, parameters)
OperatorDefinitionparametersExpressionResultType
absreturns the absolute value of the resultfollow the input expression
ceilreturns the smallest integer value that is greater or equal to the resultfollow the input expression
floorreturns the largest integer value that is greater or equal to the resultfollow the input expression
roundreturns result round to specific decimal placesplaces: a positive integer specific decimal places of the resultfollow the input expression

For example:
If we want to query the average value of the service_cpm metric in seconds,
and round the result to 2 decimal places, we can use the following expression:

round(service_cpm / 60 , 2)

Result Type

The different operators could impact the ExpressionResultType, please refer to the above table.

TopN Operation

TopN Operation takes an expression and performs TopN calculation on its results.

Expression:

top_n(<metric_name>, <top_number>, <order>)

top_number is the number of the top results, should be a positive integer.

order is the order of the top results. The value of order can be asc or des.

For example:
If we want to query the top 10 services with the highest service_cpm metric value, we can use the following expression:

top_n(service_instance_cpm, 10, des)

Result Type

According to the type of the metric, the ExpressionResultType of the expression will be SORTED_LIST or RECORD_LIST.

Relabel Operation

Relabel Operation takes an expression and replaces the label values with new label values on its results.

Expression:

relabel(Expression, _='<new_label_value_1>,...')

_ is the new label of the metric after the label is relabeled, the order of the new label values should be the same as the order of the label values in the input expression result.

For example:
If we want to query the service_percentile metric with the label values 0,1,2,3,4, and rename the label values to P50,P75,P90,P95,P99, we can use the following expression:

relabel(service_percentile{_='0,1,2,3,4'}, _='P50,P75,P90,P95,P99')

Result Type

Follow the input expression.

AggregateLabels Operation

AggregateLabels Operation takes an expression and performs an aggregate calculation on its Labeled Value Metrics results. It aggregates a group of TIME_SERIES_VALUES into a single TIME_SERIES_VALUES.

Expression:

aggregate_labels(Expression, parameter)
parameterDefinitionExpressionResultType
avgcalculate avg value of a Labeled Value MetricsTIME_SERIES_VALUES
sumcalculate sum value of a Labeled Value MetricsTIME_SERIES_VALUES
maxselect the maximum value from a Labeled Value MetricsTIME_SERIES_VALUES
minselect the minimum value from a Labeled Value MetricsTIME_SERIES_VALUES

For example:
If we want to query all Redis command total rates, we can use the following expression(total_commands_rate is a metric which recorded every command rate in labeled value):

aggregate_labels(total_commands_rate, SUM)

Result Type

The ExpressionResultType of the aggregateLabels operation is TIME_SERIES_VALUES.

Logical Operation

ViewAsSequence Operation

ViewAsSequence operation represents the first not-null metric from the listing metrics in the given prioritized sequence(left to right). It could also be considered as a short-circuit of given metrics for the first value existing metric.

Expression:

view_as_seq([<expression_1>, <expression_2>, ...])

For example:
if the first expression value is empty but the second one is not empty, it would return the result from the second expression.
The following example would return the content of the service_cpm metric.

view_as_seq(not_existing, service_cpm)

Result Type

The result type is determined by the type of selected not-null metric expression.

Expression Query Example

Labeled Value Metrics

service_percentile{_='0,1'}

The example result is:

{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": [{"key": "_", "value": "0"}]},"values": [{"id": "1691658000000", "value": "1000", "traceID": null}, {"id": "1691661600000", "value": 2000, "traceID": null}]},{"metric": {"labels": [{"key": "_", "value": "1"}]},"values": [{"id": "1691658000000", "value": "2000", "traceID": null}, {"id": "1691661600000", "value": 3000, "traceID": null}]}]}}
}

If we want to transform the percentile value unit from ms to s the expression is:

service_percentile{_='0,1'} / 1000
{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": [{"key": "_", "value": "0"}]},"values": [{"id": "1691658000000", "value": "1", "traceID": null}, {"id": "1691661600000", "value": 2, "traceID": null}]},{"metric": {"labels": [{"key": "_", "value": "1"}]},"values": [{"id": "1691658000000", "value": "2", "traceID": null}, {"id": "1691661600000", "value": 3, "traceID": null}]}]}}
}

Get the average value of each percentile, the expression is:

avg(service_percentile{_='0,1'})
{"data": {"execExpression": {"type": "SINGLE_VALUE","error": null,"results": [{"metric": {"labels": [{"key": "_", "value": "0"}]},"values": [{"id": null, "value": "1500", "traceID": null}]},{"metric": {"labels": [{"key": "_", "value": "1"}]},"values": [{"id": null, "value": "2500", "traceID": null}]}]}}
}

Calculate the difference between the percentile and the average value, the expression is:

service_percentile{_='0,1'} - avg(service_percentile{_='0,1'})
{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": [{"key": "_", "value": "0"}]},"values": [{"id": "1691658000000", "value": "-500", "traceID": null}, {"id": "1691661600000", "value": 500, "traceID": null}]},{"metric": {"labels": [{"key": "_", "value": "1"}]},"values": [{"id": "1691658000000", "value": "-500", "traceID": null}, {"id": "1691661600000", "value": 500, "traceID": null}]}]}}
}

Calculate the difference between the service_resp_time and the service_percentile, if the service_resp_time result is:

{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": []},"values": [{"id": "1691658000000", "value": "2500", "traceID": null}, {"id": "1691661600000", "value": 3500, "traceID": null}]}]}}
}

The expression is:

service_resp_time - service_percentile{_='0,1'}
{"data": {"execExpression": {"type": "TIME_SERIES_VALUES","error": null,"results": [{"metric": {"labels": [{"key": "_", "value": "0"}]},"values": [{"id": "1691658000000", "value": "1500", "traceID": null}, {"id": "1691661600000", "value": "1500", "traceID": null}]},{"metric": {"labels": [{"key": "_", "value": "1"}]},"values": [{"id": "1691658000000", "value": "500", "traceID": null}, {"id": "1691661600000", "value": "500", "traceID": null}]}]}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/82511.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

stm32----ADC模数转换

一、ADC介绍 ADC&#xff0c;即模数转换器&#xff0c;它可以将模拟信号转化为数字信号。在stm32种一般有3个ADC&#xff0c;每个ADC有18个通道。 12位ADC是一种逐次逼近型模拟数字转换器&#xff0c;它有多达18个通道&#xff0c;可测量16个外部和两个内部信号源。各个通道的A…

Linux文件管理命令

Linux命令行 命令空格参数(可写可不写)空格文件(可写可不写)ls/opt 根目录下的opt文件夹ls-a 显示所有文件及隐藏文件/optls -l 详细输出文件夹内容 ls -h 输出文件大小(MB...)ls--full-time 完整时间格式输出ls-d 显示文件夹本身信息&#xff0c;不输出内容ls-t 根据最后修改…

js如何实现一个简单的节流函数?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 实现简单的节流函数⭐ 写在最后 ⭐ 专栏简介 前端入门之旅&#xff1a;探索Web开发的奇妙世界 记得点击上方或者右侧链接订阅本专栏哦 几何带你启航前端之旅 欢迎来到前端入门之旅&#xff01;这个专栏是为那些对Web开发感兴趣、刚刚踏入…

巨人互动|Facebook海外户Facebook有什么功能

Facebook是一款国际化的用于聊天的软件&#xff0c;Facebook一般情况下用户可以在其共享照片、发布评论以及在网络上发布新闻或者其他有趣内容的链接&#xff0c;观看短视频或者实时聊天等。那么Facebook也拥有广泛的功能和特点。 巨人互动|Google海外户&Google内容定位介绍…

修改root 用户的密码

修改root账号密码和有效期 一般linux系统默认root是没有密码的&#xff0c;需要启动的时候用户自己设置&#xff0c;这里介绍一种不用passwd指令添加或者修改root密码的方式 在root账户的记录中&#xff0c;用“:”符号分隔开的第二个字段通常是密码字段&#xff0c;将该字段的…

SQLite 学习笔记1 - 简介、下载、安装

SQLite 简介 SQLite是一款非常轻量级的关系数据库系统&#xff0c;支持多数SQL92标准。SQLite 是世界上使用最广泛的数据库引擎。SQLite 内置于所有手机和大多数计算机中&#xff0c;并捆绑在人们每天使用的无数其他应用程序中。 SQLite 是一个由C语音开发的嵌入式库&#xff…

lv4 嵌入式开发-9 静态库与动态库的使用

目录 1 库的概念 2 库的知识 3 静态库特点 4 静态库 4.1静态库创建 4.2 编译生成目标文件 4.3 创建静态库 hello 4.4 查看库中符号信息 4.5 链接静态库 5 共享库特点 6 共享库 6.1 共享库创建 6.2 编译生成目标文件 6.3 创建共享库 common 6.4为共享库文件创建…

分布式调度 Elastic-job

分布式调度 Elastic-job 1.概述 1.1什么是任务调度 我们可以思考一下下面业务场景的解决方案: 某电商平台需要每天上午10点&#xff0c;下午3点&#xff0c;晚上8点发放一批优惠券某银行系统需要在信用卡到期还款日的前三天进行短信提醒某财务系统需要在每天凌晨0:10分结算…

04-Flask-新版Flask运行方式

新版Flask运行方式 前言老版本运行方式新版本运行方式命令行方式运行pycharm运行 前言 本篇来学习下新版Flask运行方式 老版本运行方式 app.run()&#xff1a;1.0之前版本 # -*- coding: utf-8 -*- # Time : 2023/9/16 # Author : 大海# 导入flask from flask import F…

SWC 流程

一个arxml 存储SWC &#xff08;可以存多个&#xff0c;也可以一个arxml存一个SWC&#xff09;一个arxml 存储 composition &#xff08;只能存一个&#xff09;一个arxml 存储 system description (通过import dbc自动生成system) 存储SWC和composition的arxml文件分开&#…

树回归CART

之前线性回归创建的模型需要拟合所有的样本点&#xff0c;但数据特征众多&#xff0c;关系复杂时&#xff0c;构建全局模型就很困难。之前构建决策树使用的算法是ID3。 ID3 的做法是每次选取当前最佳的特征来分割数据&#xff0c;并按照该特征的所有可能取值来切分。也就是说&…

第2章_freeRTOS入门与工程实践之单片机程序设计模式

本教程基于韦东山百问网出的 DShanMCU-F103开发板 进行编写&#xff0c;需要的同学可以在这里获取&#xff1a; https://item.taobao.com/item.htm?id724601559592 配套资料获取&#xff1a;https://rtos.100ask.net/zh/freeRTOS/DShanMCU-F103 freeRTOS系列教程之freeRTOS入…

目标跟踪:Mobile Vision Transformer-based Visual Object Tracking

论文作者&#xff1a;Goutam Yelluru Gopal,Maria A. Amer 作者单位&#xff1a;Concordia University 论文链接&#xff1a;https://arxiv.org/pdf/2309.05829v1.pdf 项目链接&#xff1a;https://github.com/goutamyg/MVT 内容简介&#xff1a; 1&#xff09;方向&#…

【iOS】单例模式

文章目录 前言一、单例模式简介二、单例模式优缺点优点缺点 三、模式介绍1.懒汉模式2. 饿汉模式 总结 前言 在最初进行OC的学习时笔者了解过单例模式的基本使用&#xff0c;现撰写博客加深对单例模式的理解 一、单例模式简介 单例模式是一种常见的设计模式&#xff0c;其主要…

基于HOG特征提取和GRNN神经网络的人脸表情识别算法matlab仿真,测试使用JAFFE表情数据库

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 1.HOG特征提取 2.GRNN神经网络 3.JAFFE表情数据库 5.算法完整程序工程 1.算法运行效果图预览 2.算法运行软件版本 matlab2022a 3.部分核心程序 .....................................…

Vue3 菜鸟入门(二)超详细:基本框架 模板语法和指令

【学习笔记】Vue3 菜鸟入门&#xff08;二&#xff09;超详细&#xff1a;基本框架 模板语法和指令 关键词&#xff1a;Vue 、Vue 3、Java、Spring Boot、Idea、数据库、一对一、培训、教学本文主要内容含Vue 基本框架 模板语法、指令计划1小时完成&#xff0c;请同学尽量提前…

nginx入门

概述/简介 Nginx 是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器&#xff0c;在 BSD-like 协议下发行,具有高性能、高可靠性、丰富的模块化支持和简单易用的优势。 应用场景 动静分离: 为了加快网站的解析速度&#xff0c;我们可以把动态页面和静态页面分散到…

cutree 算法

传播 ​ 由于块与块之间具有参考关系&#xff0c;提升被参考块的质量&#xff0c;可以改善后续参考块的质量 ​ Pn1帧中CU0,1完全参考Pn的CU1,1。且Pn1帧中CU0,1块帧内预测和帧间预测的代价分别为 c x , y n 1 ( 0 , 0 ) c_{x,y}^{n1}(0,0) cx,yn1​(0,0)和 c x , y n 1 ( d…

2023Node.js零基础教程(小白友好型),nodejs新手到高手,(一)NodeJS入门

写在开始前 在无尽的代码汪洪中&#xff0c;闪耀着一抹绚丽的光芒。它叫做Web前端开发&#xff01; HTML是我们的魔法笔&#xff0c;是创造力的源泉。它将我们的思绪化为标签&#xff0c;将我们的想象变为元素。 在无尽的标签组合中&#xff0c;我们创造出独特的网页&#xff…

Webserver项目解析

一.webserver的组成部分 Buffer类 用于存储需要读写的数据 Channel类 存储文件描述符和相应的事件&#xff0c;当发生事件时&#xff0c;调用对应的回调函数 ChannelMap类 Channel数组&#xff0c;用于保存一系列的Channel Dispatcher 监听器&#xff0c;可以设置为epo…