当前位置:网站首页>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.121You 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=7query_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
/apiWhen 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_countalsomethodLabel is notPOSTSequence .demo_api_request_duration_seconds_count{method!="POST"}3. Use
demo_memory_usage_bytesIndex query one hour ago 1 Available in the minute time range Free Memory .demo_memory_usage_bytes{type="free"}[1m] offset 1h
边栏推荐
- Feature pyramid networks for object detection
- Leetcode 128 longest continuous sequence (hash set)
- 5、【WebGIS实战】软件操作篇——服务发布及权限管理
- 242. 有效的字母异位词
- Pytorch training deep learning network settings CUDA specified GPU visible
- 389. 找不同
- multiple linear regression
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- 5. [WebGIS practice] software operation - service release and permission management
- ECMAScript 6.0
猜你喜欢

How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars

AfxMessageBox和MessageBox的用法

复习专栏之---消息队列

Addition without addition, subtraction, multiplication and division

How to achieve 0 error (s) and 0 warning (s) in keil5

Jeecgboot output log, how to use @slf4j

报错:Plug-ins declaring extensions or extension points must set the singleton directive to true

过滤器 Filter

Thread data sharing and security -threadlocal

Idea plug-in backup table
随机推荐
Implement pow (x, n) function
Binary tree god level traversal: Morris traversal
完全背包问题
服务器渲染技术jsp
还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板
Golang multi graph generation gif
166. 分数到小数
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
C语言的sem_t变量类型
监听器 Listener
multiple linear regression
Unexpected token o in JSON at position 1 ,JSON解析问题
[reach out to Party welfare] developer reload system sequence
GCC usage, makefile summary
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
Asgnet paper and code interpretation 2
Ouc2021 autumn - Software Engineering - end of term (recall version)
Addition without addition, subtraction, multiplication and division
Research on target recognition and tracking based on 3D laser point cloud