PromQL

基本信息

  1. http_requests_total{job="prometheus",group="canary"}

=: Select labels that are exactly equal to the provided string.
!=: Select labels that are not equal to the provided string.
=~: Select labels that regex-match the provided string (or substring).
!~: Select labels that do not regex-match the provided string (or substring).
http_requests_total{environment=~"staging|testing|development",method!="GET"}

     {job=~".*"} # Bad!
     {job=~".+"}              # Good!
     {job=~".*",method="get"} # Good!
  1. 标签匹配器也可以通过匹配内部name标签应用到度量名称。 例如,表达式http_requests_total等价于{__name __ =“http_requests_total”}。 除了=(!=,=〜,!〜)以外的Matchers也可以使用。 以下表达式选择所有具有以job:开头的名称的度量
    {__name__=~"^job:.*"}

  2. 时间范围
    http_requests_total{job="prometheus"}[5m]

  3. 偏移修饰符

偏移修改器允许更改查询中单个即时和范围向量的时间偏移量。

例如,以下表达式返回相对于当前查询评估时间的过去5分钟的http_requests_total值:
http_requests_total offset 5m
请注意,偏移量修改器始终需要立即跟随选择器,即以下内容是正确的:

sum(http_requests_total{method="GET"} offset 5m) // GOOD.

sum(http_requests_total{method="GET"}) offset 5m // INVALID.

这返回http_requests_total在一周前的5分钟速率:
rate(http_requests_total[5m] offset 1w)

运算

  1. + (addition)
    - (subtraction)
    * (multiplication)
    / (division)
    % (modulo)
    ^ (power/exponentiation)

== (equal)
!= (not-equal)
> (greater-than)
< (less-than)
>= (greater-or-equal)
<= (less-or-equal)

method_code:http_errors:rate5m{method="get", code="500"}  24
method_code:http_errors:rate5m{method="get", code="404"}  30
method_code:http_errors:rate5m{method="put", code="501"}  3
method_code:http_errors:rate5m{method="post", code="500"} 6
method_code:http_errors:rate5m{method="post", code="404"} 21

method:http_requests:rate5m{method="get"}  600
method:http_requests:rate5m{method="del"}  34
method:http_requests:rate5m{method="post"} 120

example-query
method_code:http_errors:rate5m{code="500"} / ignoring(code) method:http_requests:rate5m

sum(http_requests_total) without (instance)
sum(http_requests_total)
count_values("version", build_version)
topk(5, http_requests_total)

你可能感兴趣的:(PromQL)