如何在单个 Grafana 面板中使用来自多个测量的数据?

发布于 2025-01-12 16:57:57 字数 2020 浏览 4 评论 0原文

我正在尝试在 Grafana(版本 6.6.2 - 假设升级是最后的手段,但如果有必要,出于解决此问题的目的)创建一个仪表板,它可以表示 Java Virtual 使用的总可用内存的百分比机器运行我的进程。我遇到的问题如下:

JVM 内存使用情况全图JVM 内存max

我已经使用了 Springboot 执行器的指标,并使用 Micrometer 将它们导入到 Influx 数据库中,但在此过程中,它已将我想在计算中使用的两个值存储为两个不同的测量值。 jvm_memory_usedjvm_memory_max


我最初的想法是简单地对这两个测量调用 SELECT 来获取我想要的值,然后除以“used”/“max”并将该值乘以 100 即可得到要显示的百分比。不幸的是,当我尝试手动执行此操作时,我遇到了语法错误,并且我不确定是否可以使用 Grafana 的查询生成器来执行此操作。

我知道语法不正确,但我对 InfluxQL 不够熟悉,不知道如何正确构建此查询。这是我尝试过的:(

(SELECT last("value")
    FROM "jvm_memory_used" 
    WHERE ("area" = 'heap') 
    AND $timeFilter 
    GROUP BY time($__interval) fill(null)
) /
(SELECT last("value")
    FROM "jvm_memory_max" 
    WHERE ("area" = 'heap') 
    AND $timeFilter 
    GROUP BY time($__interval) fill(null)
)

ANDGROUP BY 是 Grafana 查询生成器默认值的结果,我不确定它们是否必要或不)

我假设我的括号和除法过程是非法的,但我不知道如何解决它。


如何从不同的表中划分这两个值?

编辑:我已经稍微进一步了,但似乎有一个新问题。我现在发送以下查询:

SELECT 100 * (last("used") / sum("max")) AS "percentUsed" 
    FROM(
        SELECT last("value") AS "used" 
            FROM "jvm_memory_used" 
            WHERE ("area" = 'heap')
            AND $timeFilter
    ),(
        SELECT last("value") AS "max" 
            FROM "jvm_memory_max" 
            WHERE ("area" = 'heap')
            AND $timeFilter
    )  
    GROUP BY time($__interval) fill(null)

我得到的结果是这样的: 输入图片此处描述

我现在如何才能让此查询仅返回一个包含数据的仪表,而不是两个包含空值的仪表?

我已接受适用于 Grafana 版本的答案7.如果还有其他不涉及更新Grafana版本的答案,请一并提供!

I am attempting to create a gauge panel in Grafana (Version 6.6.2 - presume that upgrading is a last resort, but possible if necessary, for the purposes of this problem) that can represent the percentage of total available memory used by the Java Virtual Machine running a process of mine. the problem that I am running into is the following:

JVM Memory Usage full picture
JVM Memory max

I have used Springboot actuator's metrics and imported them into an Influx database with Micrometer, but in the process, it has stored the two values that I would like to use in my calculation into two different measurements. jvm_memory_used and jvm_memory_max


My initial Idea was to simply call a SELECT on both of the measurements to get the value that I want, and then divide the "used" / "max" and multiply that value by 100 to get the percentage to display. Unfortunately I run into syntax errors when I try to do this manually, and I am unsure if I can do this using Grafana's query builder.

I know that the syntax is incorrect, but I am not familiar enough with InfluxQL to know how to properly structure this query. Here is what I had tried:

(SELECT last("value")
    FROM "jvm_memory_used" 
    WHERE ("area" = 'heap') 
    AND $timeFilter 
    GROUP BY time($__interval) fill(null)
) /
(SELECT last("value")
    FROM "jvm_memory_max" 
    WHERE ("area" = 'heap') 
    AND $timeFilter 
    GROUP BY time($__interval) fill(null)
)

(The AND and GROUP BY are present as a result of the default values from Grafana's query builder, I am not sure whether they are necessary or not)

I'm assuming that my parenthesis and division process is illegal, but I am not sure how to resolve it.


How can I divide these two values from separate tables?

EDIT: I have gotten slightly further but it seems that there is a new issue. I now have the following query that I am sending in:

SELECT 100 * (last("used") / sum("max")) AS "percentUsed" 
    FROM(
        SELECT last("value") AS "used" 
            FROM "jvm_memory_used" 
            WHERE ("area" = 'heap')
            AND $timeFilter
    ),(
        SELECT last("value") AS "max" 
            FROM "jvm_memory_max" 
            WHERE ("area" = 'heap')
            AND $timeFilter
    )  
    GROUP BY time($__interval) fill(null)

and the result I get is this:
enter image description here

How can I now get this query to return only one gauge with data, instead of two with nulls?

I've accepted an answer that works for versions of Grafana after 7. If there are any other answers that arise that do not involve updating the version of Grafana, please provide them as well!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-01-19 16:57:57

我对 Influx 没有特别的经验,但由于您的问题是如何使用/组合 Grafana 面板的两个测量(查询结果),我可以告诉您一种方法:

您可以使用 转换。这样,您就可以保留两个单独的查询。使用转换模式二元运算 您可以简单地将您的一个值除以另一个值。

在您的具体情况下,要将结果显示为百分比,您可以使用百分比(0.0-1.0)作为单位,您应该已经完成​​了您的目标。

I am not particulary experienced with Influx, but since your question is how to use/combine two measurements (query results) for a Grafana panel, I can tell you about one approach:

You can use a transformation. By that, you can keep two separate queries. With the transformation mode binary operation you can simply divide one of your values by the other one.

In your specific case, to display the result as percentage, you can then use Percent (0.0-1.0) as unit and you should have accomplished your goal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文