Ad Widget

Collapse

Multiple metrics in Prometheus LLD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xaban
    Junior Member
    • Aug 2021
    • 4

    #1

    Multiple metrics in Prometheus LLD

    I created the following LLD:
    - Name: Prometheus LLD
    - Type: Dependent Item
    - Key: lld_prom
    - Master: Selected the HTTP Item which I created

    Preprocessing:
    - Prometheus to JSON: kube_deployment_status_replicas_available{namespac e="default",deployment=~".*"}

    LLD Macros:
    {#METRIC} -> $['name']
    {#POD} -> $.labels['deployment']

    Within this LLD I created an Item Prototype:
    - Name: Metric: {#METRIC} - Pod: {#POD}
    - Key: replicas_avail[{#POD}]

    Preprocessing:
    - Prometheus pattern: {#METRIC}{namespace="default",deployment="{#POD}"}

    This works great and items are being created.

    Now my question / problem:

    As you can see, I am using the metric "kube_deployment_status_replicas_available", which returns the available replica's of a deployment.
    The same Prometheus has another metric too, which is "kube_deployment_spec_replicas". This metric returns the amount of replica's that should be available.
    I want have an Item Prototype too for this metric, so at the end I can create a Trigger Prototype, so I can do something: replicas_available>spec_replicas.

    Is this possible, and how?

    Thanks!
  • Glencoe
    Zabbix developer
    • Oct 2019
    • 152

    #2
    There is one theoretical problem with comparing discovered metrics this way. kube_deployment_status_replicas_available{} is not guaranteed to have the same combinations of namespaces/deployments as kube_deployment_spec_replicas{} at the protocol level. Maybe K8s takes care of this but this is something to keep in mind.

    That being said, the idea is to create an LLD rule that creates JSON from one of the metrics but have two item prototypes (with fixed names instead of {#METRIC}) and one trigger for this rule.

    Suppose, you need to compare incoming and outgoing traffic reported by node_exporter: node_network_receive_bytes_total vs node_network_transmit_bytes_total:

    1. Create dependent discovery rule with Prometheus preprocessing:

    Click image for larger version

Name:	Screenshot 2021-09-02 at 16.43.37.png
Views:	730
Size:	77.6 KB
ID:	430865

    In this case we need to map just one LLD macro:

    Click image for larger version

Name:	Screenshot 2021-09-02 at 17.04.03.png
Views:	687
Size:	70.7 KB
ID:	430871

    2. Add two item prototypes:

    Click image for larger version

Name:	Screenshot 2021-09-02 at 16.52.24.png
Views:	696
Size:	95.1 KB
ID:	430868

    ... with standard "Prometheus pattern" preprocessing:

    Click image for larger version

Name:	Screenshot 2021-09-02 at 17.07.27.png
Views:	684
Size:	67.9 KB
ID:	430872

    3. Add one trigger prototype that refers to both items:

    Click image for larger version

Name:	Screenshot 2021-09-02 at 16.57.43.png
Views:	681
Size:	117.2 KB
ID:	430870

    Attached Files

    Comment

    • Glencoe
      Zabbix developer
      • Oct 2019
      • 152

      #3
      4. Get the result:

      Click image for larger version

Name:	Screenshot 2021-09-02 at 17.10.42.png
Views:	687
Size:	191.8 KB
ID:	430875

      Click image for larger version

Name:	Screenshot 2021-09-02 at 17.11.07.png
Views:	688
Size:	135.4 KB
ID:	430876

      Comment

      • xaban
        Junior Member
        • Aug 2021
        • 4

        #4
        Glencoe your help is much appreciated, that is exactly I was looking for!

        Comment

        Working...