当前位置:网站首页>Promql select time series
Promql select time series
2022-07-01 03:41:00 【Foxconn quality inspector zhangquandan】
Instantaneous vector , Interval vector , Instantaneous query , Interval query .
Request URL: http://139.198.166.235:9090/api/v1/query?query=demo_api_http_requests_in_progress&time=1644905624.121
You can see that this is a query promql The interface of ,query The parameter is actually promql A statement of ,time In fact, it is the timestamp of the evaluation , This only contains one promql A query such as a statement and a timestamp is actually a transient query .
The result is an instantaneous vector .
This is also a transient query , Only the result of instantaneous query is an interval vector .
The result of an instantaneous query may be an instantaneous vector , It could also be an interval vector . stay table All queries in the internal view are instantaneous queries .
If you switch to Graph Come here , Or the previous query , You can see that the interface has changed
Request URL: http://139.198.166.235:9090/api/v1/query_range?query=demo_api_http_requests_in_progress&start=1644904540.348&end=1644906340.348&step=7
query_range This is a range query , Or interval query . Because you need to draw , So it's not a point , Is within a time frame .
stay granph All the queries are interval queries .
Choose a time series
In this section, we will learn how to select data in different ways , How to filter data based on tags in a single timestamp or over a period of time , And how to use mobile time to select data .
Filter indicator name
The simplest PromQL Query is to directly select the sequence with the specified indicator name , for example , The following query will return all with indicator names demo_api_request_duration_seconds_count
Sequence :
demo_api_request_duration_seconds_count
The query will Returns a number of sequences with the same indicator name , But there are different label combinations instance、job、method、path and status etc. . The output is as follows :
Filter by tag
If we only query demo_api_request_duration_seconds_count
There is method="GET"
The index sequence of the tag , You can add this filter condition with braces after the indicator name :
demo_api_request_duration_seconds_count{method="GET"}
{__name__="demo_api_request_duration_seconds_count",instance="192.168.100.5:10000",method="GET",status="200"}
In addition, we You can also use commas to combine multiple label matchers :
demo_api_request_duration_seconds_count{instance="demo-service-0:10000",method="GET",job="demo"}
Above will get demo Under the task demo-service-0:10000
The instance And method="GET"
Index series data :
It should be noted that when multiple matching conditions are combined , It is to filter the time series that all conditions are satisfied .
In addition to equal matching ,Prometheus Several other matcher types are also supported :
!=
: It's not equal to=~
: Regular Expression Matching!~
: Regular expressions don't match
Even we can omit the indicator name completely , For example, directly query all path
Label with /api
All sequences at the beginning :
{path=~"/api.*"}
The query will get some sequences with different indicator names :
Be careful : Prometheus Regular expressions in always match against complete strings rather than partial strings . therefore , Match any with
/api
When opening the path , There is no need to^
start , But you need to add at the end.*
, This will matchpath="/api"
This sequence .
We said before that in Prometheus Inside , The index name is essentially a name __name__
The characteristic label of , So search demo_api_request_duration_seconds_count
In fact, it is equivalent to the following query method :
{__name__="demo_api_request_duration_seconds_count"}
The selector written in the above way , You can get one Instantaneous vector , It contains a single... Of all the selected sequences Latest value .
In fact, some functions require you not to pass a single value , Instead, it passes a sequence of values over a period of time , That is, the interval vector . At this time, we can add a [< Numbers >< Company >]
Duration specifier of form , Change the immediate vector selector to the range vector selector ( for example [5m]
Express 5 minute ).
For example, to query the latest 5 Minutes of available memory , You can execute the following query statement :
demo_memory_usage_bytes{type="free"}[5m]
You will get the query result shown below : This is the interval vector , It contains multiple samples , Interval vectors cannot go graph To draw , That is, at the same time
The valid time units that can be used are :
ms
- milliseconds
- secondm
- minuteh
- Hoursd
- Gody
- year
Sometimes we need to access past data in a time-lapse way , Usually used to compare with current data . To move past data to the current location , have access to offset <duration>
Modifiers are added to any range or immediate sequence selector to query ( for example my_metric offset 5m
or my_metric[1m] offset 7d
).
for example , To select the memory available one hour ago , You can use the following query statement :
demo_memory_usage_bytes{type="free"} offset 1h
At this time, the query value is the data one hour ago :
practice :
1. Build a query , Select all time series .
{job!=""}
perhaps :
{__name__=~".+"}
2. Build a query , Query all indicators whose names are
demo_api_request_duration_seconds_count
alsomethod
Label is notPOST
Sequence .demo_api_request_duration_seconds_count{method!="POST"}
3. Use
demo_memory_usage_bytes
Index query one hour ago 1 Available in the minute time range Free Memory .demo_memory_usage_bytes{type="free"}[1m] offset 1h
边栏推荐
- Feign remote call and getaway gateway
- Idea plug-in backup table
- 后台系统右边内容如何出现滚动条和解决双滚动条的问题
- C语言的sem_t变量类型
- [deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
- 详解Spark运行模式(local+standalone+yarn)
- 30. 串联所有单词的子串
- pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
- 5. [WebGIS practice] software operation - service release and permission management
- 【伸手党福利】开发人员重装系统顺序
猜你喜欢
文件上传下载
pytorch训练深度学习网络设置cuda指定的GPU可见
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
Pytorch training deep learning network settings CUDA specified GPU visible
5. [WebGIS practice] software operation - service release and permission management
后台系统右边内容如何出现滚动条和解决双滚动条的问题
Edlines: a real time line segment detector with a false detection control
How to achieve 0 error (s) and 0 warning (s) in keil5
Sort linked list (merge sort)
不用加减乘除实现加法
随机推荐
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
Cookie&Session
Gorilla/mux framework (RK boot): RPC error code design
Ridge regression and lasso regression
Design of serial port receiving data scheme
Pathmeasure implements loading animation
二叉树神级遍历:Morris遍历
GCC usage, makefile summary
30. 串联所有单词的子串
You cannot right-click F12 to view the source code solution on the web page
318. 最大单词长度乘积
Research on target recognition and tracking based on 3D laser point cloud
Golang multi graph generation gif
Learning notes for introduction to C language multithreaded programming
Develop industrial Internet with the technical advantages of small programs
How to use hybrid format to output ISO files? isohybrid:command not found
208. 实现 Trie (前缀树)
leetcode 1818 绝对值,排序,二分法,最大值
Review column - message queue
Sort linked list (merge sort)