简体   繁体   English

如何区分两种不同的prometheus指标?

[英]How get difference between 2 different prometheus metrics?

Consider metric examples: 考虑度量示例:

increase(application_executor_recordsWritten[20m])
increase(kafka_server_brokertopicmetrics_messagesin_total{topic="my_topic"}[20m])

If I execute those metrics separate on prometheus graph - everything works. 如果我在prometheus图上单独执行这些指标 - 一切正常。 But when try something like: 但是当尝试类似的东西:

increase(application_executor_recordsWritten[20m]) -  increase(kafka_server_brokertopicmetrics_messagesin_total{topic="my_topic"}[20m])

I got No datapoints error . No datapoints error

  1. May be it happens because application_executor_recordsWritten received for last 1 hour while kafka_server_brokertopicmetrics_messagesin_total is received for 6+ hours. 可能是因为application_executor_recordsWritten收到了最近1小时,而kafka_server_brokertopicmetrics_messagesin_total收到了6个多小时。
  2. May it happens because those metric have different "gather settings", consider prometheus console output: 可能是因为这些指标有不同的“收集设置”,请考虑prometheus控制台输出:

    application_executor_recordsWritten application_executor_recordsWritten

    {app_name="app-name",exported_instance="application_111111111111111111",exported_job="application_111111111111111111",instance="XX.XXX.X.XX",job="job_name",number="1",role="executor"} {APP_NAME = “应用程序名”,exported_instance = “application_111111111111111111”,exported_job = “application_111111111111111111”,例如= “XX.XXX.X.XX”,工作= “JOB_NAME”,数= “1”,角色= “执行人” }

    kafka_server_brokertopicmetrics_messagesin_total kafka_server_brokertopicmetrics_messagesin_total

    {instance="XX.XXX.X.XX",job="job_name",topic="my_topic"} {例如= “XX.XXX.X.XX”,工作= “JOB_NAME”,主题= “my_topic”}

Prometheus use something like ignore(???) keyword, but I can not figure out how does it work and how apply it for these metric. Prometheus使用像ignore(???)关键字,但我无法弄清楚它是如何工作的以及如何将它应用于这些指标。

Any ideas how to perform metrics difference? 任何想法如何执行指标差异? What is the correct syntax for this? 这个的正确语法是什么?

In PromQL, arithmetic binary operators between two metric ranges (aka vectors) are subject to vector matching : the operation is only applied on entries that have the same exact label set (name and avalue). 在PromQL中,两个度量范围(也称为向量)之间的算术二元运算符受矢量匹配的约束:该操作仅应用于具有相同精确标签集(名称和值)的条目。

If there is aa difference and no values are paired, your get the infamous No data point error. 如果存在差异并且没有配对值,则会得到臭名昭着的无数No data point错误。

If you want to make them match, you have to 如果你想让它们匹配,你必须

  • either ignoring some labels that do not match ( metric1 - ignoring(a_lone_label) metric2 ) 忽略一些不匹配的标签metric1 - ignoring(a_lone_label) metric2
  • or indicating on which label perform the match ( metric1 - on(common_label_name_and_value) metric2 ) 或指示哪个标签执行匹配metric1 - on(common_label_name_and_value) metric2

In the examples you gave, it is unclear what should match. 在您给出的示例中,不清楚应该匹配什么。 I would say instance and job ; 我会说instancejob ; it could be: 它可能是:

increase(application_executor_recordsWritten[...]) - on (job,instance) increase(kafka_server_brokertopicmetrics_messagesin_total{topic="my_topic"}[...])

If you have one side of the operator containing elements that should be paired with more than one element of the other side (call one-to-many matching), you have to indicate which side of the operator (right or left) has more entries: using group_<side:rigth|left> . 如果运算符的一侧包含应与另一侧的多个元素配对的元素(调用一对多匹配),则必须指示运算符的哪一侧(右侧或左侧)具有更多条目:使用group_<side:rigth|left>

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

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