Skip to content

Commit e43aaad

Browse files
添加prometheus偏移量修饰符
1 parent 7399697 commit e43aaad

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

k8s/prometheus.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ curl -X POST http://localhost:9090/-/reload
4343
- labeldrop:针对所有标签来匹配regex,任何匹配的标签将从标签集中删除。
4444

4545
### 配置
46+
47+
#### flag
48+
[flag参数](https://prometheus.io/docs/prometheus/latest/command-line/prometheus/)
49+
4650
```yaml
4751
# 全局配置
4852
global:
@@ -366,7 +370,7 @@ http_request_total{} # 瞬时向量表达式,选择当前最新的数据
366370
http_request_total{}[5m] # 区间向量表达式,选择以当前时间为基准,5分钟内的数据
367371
```
368372

369-
#### Offset modifier  偏移修改器
373+
#### Offset modifier  偏移修饰符
370374

371375
而如果我们想查询,5分钟前的瞬时样本数据,或昨天一天的区间内的样本数据呢? 这个时候我们就可以使用位移操作,位移操作的关键字为**offset**
372376

@@ -376,6 +380,16 @@ http_request_total{}[5m] # 区间向量表达式,选择以当前时间为基
376380
http_request_total{} offset 5m
377381
http_request_total{}[1d] offset 1d
378382
```
383+
`offset` 修饰符始终需要紧跟选择器,即以下内容是正确的:
384+
```yaml
385+
sum(http_requests_total{method="GET"} offset 5m) // GOOD.
386+
sum(http_requests_total{method="GET"}) offset 5m // INVALID.
387+
```
388+
可以结合范围向量一起使用
389+
```bash
390+
rate(http_requests_total[5m] offset 1w)
391+
```
392+
379393

380394
*支持时间位移操作*
381395

@@ -396,6 +410,29 @@ http_request_total{} offset 5m
396410
http_request_total{}[1d] offset 1d
397411
```
398412

413+
#### @ 修饰符
414+
`@` 修饰符允许更改查询中单个瞬时向量和范围向量的计算时间。传递给 `@` 修饰符的时间是一个 Unix 时间戳,以浮点字面量表示。
415+
416+
例如,以下表达式返回的值 `http_requests_total` 于 `2021-01-04T07:40:00+00:00` :
417+
 `@` 修饰符始终需要紧跟选择器
418+
```bash
419+
http_requests_total @ 1609746000
420+
```
421+
422+
与offset配合使用
423+
```
424+
# offset after @
425+
http_requests_total @ 1609746000 offset 5m
426+
# offset before @
427+
http_requests_total offset 5m @ 1609746000
428+
```
429+
430+
此外, `start()` 和 `end()` 也可以用作 `@` 修饰符的特殊值。
431+
432+
433+
434+
435+
399436
*使用聚合操作*
400437

401438
如果多个样本数据的标签不唯一(多个数据源),通过PromQL查询会有很多数据,通过聚合操作可以用来处理这些时间序列数据。
@@ -443,6 +480,9 @@ http_request_total{} # 合法
443480
{__name__=~"node_disk_bytes_read|node_disk_bytes_written"} # 合法
444481
```
445482

483+
484+
485+
446486
### PromQL 操作符
447487

448488
除了简单的按照时间排序外,PromQL还支持一些操作符, 这些操作符包括:数学运算操作符、逻辑运算符、布尔运算符等。
@@ -656,6 +696,8 @@ topk(3, bicycle_speed_meters_per_second)
656696

657697
### PromQL 内置函数
658698

699+
[内置函数](https://prometheus.io/docs/prometheus/latest/querying/functions/)
700+
659701
*计算Counter指标增长率*
660702

661703
我们知道Counter类型的监控指标其特点是只增不减,在没有发生重置(如服务器重启,应用重启)的情况下其样本值应该是不断增大的。为了能够更直观的表示样本数据的变化剧烈情况,需要计算样本的增长速率。

0 commit comments

Comments
 (0)