普罗米修斯PromQL外加入

时间:2020-08-23 08:19:22

标签: prometheus promql

我要加入两个Prometheus度量规,并在末尾保留某些类型的标签。

-Gauge 1公制样本:

from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
import random

APP_KV = """
<CanvasTest>:
    canvas:
        Color:
            rgba: 0, 1, 0, 1
        Rectangle:
            group: 'rectangle'
            size: 400, 200
            pos: self.pos
        Color:
            rgba: 1, 0, 0, 1
        Ellipse:
            group: 'ellipse'
            size: 200, 100
            pos: self.pos
"""

class CanvasTest(BoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        Clock.schedule_interval(self.test_pos, 1)
        
    def test_pos(self, *args):
        self.canvas.get_group('rectangle')[0].pos = random.randrange(1, Window.width - 400), random.randrange(1, Window.height - 200)
        self.canvas.get_group('ellipse')[0].pos = random.randrange(1, Window.width - 200), random.randrange(1, Window.height - 100)

class MainApp(App):
    def build(self):
        self.root = Builder.load_string(APP_KV)
        return CanvasTest()

if __name__ == '__main__':
    MainApp().run()

-Gauge 2指标样本:

{attnid="dfw002", hhmm="00:001",status="200", device="android_mobile", network="tnt"}

加入后,我希望指标标签在图例中显示如下内容:

{attnid="dfw002", hhmm="00:001", adr_code="24107",description="No profile found"}

(所以一切 但是hhmm字段)

如果Gauge 2指标不匹配,我只想显示Gauge 1指标,那么:

{adr_code="24107", attnid="dfw002", description="No profile found",
   device="android_mobile", network="tnt", status="200"}

没有hhmm

我想使用attnid和hhmm字段进行匹配/联接,但是我不想在末尾用hhmm求和/计数。

对于一对多关系,量规1中的1度量标准在量规2中可能有多个匹配项。

现在我正在使用此查询:

 {attnid="dfw002", device="android_mobile", network="tnt",
   status="200"}

但是结果有点多余,因为他们两个都出现了

 sum((max_over_time(adr_general_gauge{attnid=~"$AttnID", hhmm=~".*",
   device=~"$Device", network=~"$Network", status=~"$Status"}[5m])) + on
   (hhmm, attnid) group_right(network, device, status) 0*
   (max_over_time(adr_code_gauge{attnid=~"$AttnID", hhmm=~".*",
   adr_code=~"$ADR_Code", description=~".*", device=~"$Device",
   network=~"$Network"}[5m])) or on (attnid, hhmm)
   (max_over_time(adr_general_gauge{attnid=~"$AttnID", hhmm=~".*",
   device=~"$Device", network=~"$Network", status=~"$Status"}[5m]))) by
   (attnid, status, device, network, adr_code, description)

AND

{adr_code="24107", attnid="dfw002", description="No profile found",
   device="android_mobile", network="tnt", status="200"}

问题是我加入的度量标准的时间戳略有不同,因为一个日志比另一个日志晚(这就是为什么我使用max_over_time [5m]能够加入。

我真正想要的是一个if语句,如果匹配,则显示组合值,而不仅仅是显示Gauge 1指标。

例如:

{attnid="dfw002", device="android_mobile", network="tnt",
   status="200"} around the same time period but I really just want
   {adr_code="24107", attnid="dfw002", description="No profile found",
   device="android_mobile", network="tnt", status="200"}

0 个答案:

没有答案