@@ -43,6 +43,10 @@ curl -X POST http://localhost:9090/-/reload
43
43
- labeldrop:针对所有标签来匹配regex,任何匹配的标签将从标签集中删除。
44
44
45
45
### 配置
46
+
47
+ #### flag
48
+ [ flag参数] ( https://prometheus.io/docs/prometheus/latest/command-line/prometheus/ )
49
+
46
50
``` yaml
47
51
# 全局配置
48
52
global :
@@ -366,7 +370,7 @@ http_request_total{} # 瞬时向量表达式,选择当前最新的数据
366
370
http_request_total{}[5m] # 区间向量表达式,选择以当前时间为基准,5分钟内的数据
367
371
```
368
372
369
- #### Offset modifier 偏移修改器
373
+ #### Offset modifier 偏移修饰符
370
374
371
375
而如果我们想查询,5分钟前的瞬时样本数据,或昨天一天的区间内的样本数据呢? 这个时候我们就可以使用位移操作,位移操作的关键字为** offset** 。
372
376
@@ -376,6 +380,16 @@ http_request_total{}[5m] # 区间向量表达式,选择以当前时间为基
376
380
http_request_total{} offset 5m
377
381
http_request_total{}[1d] offset 1d
378
382
```
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
+
379
393
380
394
* 支持时间位移操作*
381
395
@@ -396,6 +410,29 @@ http_request_total{} offset 5m
396
410
http_request_total{}[1d] offset 1d
397
411
```
398
412
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
+
399
436
* 使用聚合操作*
400
437
401
438
如果多个样本数据的标签不唯一(多个数据源),通过PromQL查询会有很多数据,通过聚合操作可以用来处理这些时间序列数据。
@@ -443,6 +480,9 @@ http_request_total{} # 合法
443
480
{__name__=~ " node_disk_bytes_read|node_disk_bytes_written" } # 合法
444
481
```
445
482
483
+
484
+
485
+
446
486
### PromQL 操作符
447
487
448
488
除了简单的按照时间排序外,PromQL还支持一些操作符, 这些操作符包括:数学运算操作符、逻辑运算符、布尔运算符等。
@@ -656,6 +696,8 @@ topk(3, bicycle_speed_meters_per_second)
656
696
657
697
### PromQL 内置函数
658
698
699
+ [ 内置函数] ( https://prometheus.io/docs/prometheus/latest/querying/functions/ )
700
+
659
701
* 计算Counter指标增长率*
660
702
661
703
我们知道Counter类型的监控指标其特点是只增不减,在没有发生重置(如服务器重启,应用重启)的情况下其样本值应该是不断增大的。为了能够更直观的表示样本数据的变化剧烈情况,需要计算样本的增长速率。
0 commit comments