简体   繁体   English

普罗米修斯或使用rate()时

[英]Prometheus OR when using rate()

Summary 摘要

I'm trying to figure out how to properly use the OR | 我试图弄清楚如何正确使用OR | operator in a Prometheus query because my imported Grafana dashboard is not working. Prometheus查询中的运算符,因为导入的Grafana仪表板无法正常工作。

Long version 长版

I'm trying to debug a Grafana dashboard based on some data scraped from my Kubernetes pods running AppMetrics/Prometheus ; 我正在尝试根据从运行AppMetrics / Prometheus的 Kubernetes吊舱中抓取的一些数据来调试Grafana仪表板; the dashboard is here . 仪表板在这里 Basically what happens is that when the value "All" for the server is selected on the Grafana dashboard ( server is an individual pod in this case), no data appears. 基本上发生的是,当在Grafana仪表板上选择server “ All”值时(在这种情况下server是一个单独的Pod),则不会显示任何数据。 However, when I select an individual pod, then data does appear. 但是,当我选择单个吊舱时,数据确实会出现。

Here's an example of the same metric scraped from the two pods: 以下是从两个广告连播中抓取的同一指标的示例:

# HELP application_httprequests_transactions 
# TYPE application_httprequests_transactions summary
application_httprequests_transactions_sum{server="myapp-test-58d94bf78d-jdq78",app="MyApp",env="test"} 5.006965628
application_httprequests_transactions_count{server="myapp-test-58d94bf78d-jdq78",app="MyApp",env="test"} 1367
application_httprequests_transactions{server="myapp-test-58d94bf78d-jdq78",app="MyApp",env="test",quantile="0.5"} 0.000202825
application_httprequests_transactions{server="myapp-test-58d94bf78d-jdq78",app="MyApp",env="test",quantile="0.75"} 0.000279318
application_httprequests_transactions{server="myapp-test-58d94bf78d-jdq78",app="MyApp",env="test",quantile="0.95"} 0.000329862
application_httprequests_transactions{server="myapp-test-58d94bf78d-jdq78",app="MyApp",env="test",quantile="0.99"} 0.055584233

# HELP application_httprequests_transactions 
# TYPE application_httprequests_transactions summary
application_httprequests_transactions_sum{server="myapp-test-58d94bf78d-l9tdv",app="MyApp",env="test"} 6.10214788
application_httprequests_transactions_count{server="myapp-test-58d94bf78d-l9tdv",app="MyApp",env="test"} 1363
application_httprequests_transactions{server="myapp-test-58d94bf78d-l9tdv",app="MyApp",env="test",quantile="0.5"} 0.000218548
application_httprequests_transactions{server="myapp-test-58d94bf78d-l9tdv",app="MyApp",env="test",quantile="0.75"} 0.000277483
application_httprequests_transactions{server="myapp-test-58d94bf78d-l9tdv",app="MyApp",env="test",quantile="0.95"} 0.033821094
application_httprequests_transactions{server="myapp-test-58d94bf78d-l9tdv",app="MyApp",env="test",quantile="0.99"} 0.097113234

I ran the Query inspector in Grafana to find out which query it is calling, and then ran the PromQL query in Prometheus itself. 我在Grafana中运行了查询检查器,以查明它正在调用哪个查询,然后在Prometheus本身中运行了PromQL查询。 Basically, when I execute the following PromQL queries individually, they return data: 基本上,当我分别执行以下PromQL查询时,它们将返回数据:

rate(application_httprequests_transactions_count{env="test",app="MyApp",server="myapp-test-58d94bf78d-l9tdv"}[15m])*60

rate(application_httprequests_transactions_count{env="test",app="MyApp",server="myapp-test-58d94bf78d-jdq78"}[15m])*60

However, when I try to use PromQL's | 但是,当我尝试使用PromQL时| operator to combine them, I don't get data back: 运算符来合并它们,但我没有返回数据:

rate(application_httprequests_transactions_count{env="test",app="MyApp",server="myapp-test-58d94bf78d-l9tdv|myapp-test-58d94bf78d-jdq78"}[15m])*60

Here's the raw output from Grafana's query inspector: 这是Grafana的查询检查器的原始输出:

xhrStatus:"complete"

request:Object

method:"GET"
url:"api/datasources/proxy/56/api/v1/query_range?query=rate(application_httprequests_transactions_count%7Benv%3D%22test%22%2Capp%3D%22MyApp%22%2Cserver%3D%22myapp-test-58d94bf78d-jdq78%7Cmyapp-test-58d94bf78d-l9tdv%7Cmyapp-test-5b8c9845fb-7lklm%7Cmyapp-test-5b8c9845fb-8jf7n%7Cmyapp-test-5b8c9845fb-d9x5c%7Cmyapp-test-5b8c9845fb-fw4gj%7Cmyapp-test-5b8c9845fb-vtl9z%7Cmyapp-test-5b8c9845fb-vv7xv%7Cmyapp-test-5b8c9845fb-wq9bs%7Cmyapp-test-5b8c9845fb-xqfrt%7Cmyapp-test-69999d58b5-549vd%7Cmyapp-test-69999d58b5-lmp8x%7Cmyapp-test-69999d58b5-nbvt9%7Cmyapp-test-69999d58b5-qphj2%7Cmyapp-test-6b8dcc5ffb-gjjvj%7Cmyapp-test-6b8dcc5ffb-rxfk2%7Cmyapp-test-7fdf446767-bzhm2%7Cmyapp-test-7fdf446767-hp46w%7Cmyapp-test-7fdf446767-rhqhq%7Cmyapp-test-7fdf446767-wxmm2%22%7D%5B1m%5D)*60&start=1540574190&end=1540574505&step=15"

response:Object

status:"success"

data:Object

resultType:"matrix"

result:Array[0] => []

I opened a GitHub issue for this as well; 我也为此打开了一个GitHub问题。 it has a quick GIF screen recording showing what I mean: AppMetrics/Prometheus#43 它有一个快速的GIF屏幕记录,显示了我的意思: AppMetrics / Prometheus#43

| is for regular expressions, PromQL doesn't have a | 用于正则表达式,PromQL没有| operator (but it does have an or operator). 运算符(但确实有一个or运算符)。 You need to specify that the matcher is a regex rather than an exact match with =~ : 您需要指定匹配器是正则表达式,而不是=~的完全匹配项:

rate(application_httprequest_transactions_count{env="test",app="MyApp",server=~"myapp-test-58d94bf78d-l9tdv|myapp-test-58d94bf78d-jdq78"}[15m])*60

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM