基本信息
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!
標簽匹配器也可以通過匹配內部name標簽應用到度量名稱。 例如,表達式http_requests_total等價于{__name __ =“http_requests_total”}。 除了=(!=,=?,!?)以外的Matchers也可以使用。 以下表達式選擇所有具有以job:開頭的名稱的度量
{__name__=~"^job:.*"}
時間范圍
http_requests_total{job="prometheus"}[5m]
偏移修飾符
偏移修改器允許更改查詢中單個即時和范圍向量的時間偏移量。
例如,以下表達式返回相對于當前查詢評估時間的過去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)
運算
- + (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)