1

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!

Flats
  • 81
  • 1
  • 13
  • InfluxDB doesn't have table, but measurement + you can't it query with SQL, but with InfluxQL. – Jan Garaj Mar 10 '22 at 18:56
  • @JanGaraj Thanks for the edit, I've also updated the tags accordingly. As I said, I am very unfamiliar with the whole of it, lol – Flats Mar 10 '22 at 19:14
  • @JanGaraj I was looking around at your answer [here](https://stackoverflow.com/a/71319065/15836253) and I was wondering if that same thought process would apply? In that there is not a way to do this in InfluxQL at all... Am I thinking about that answer the right way? – Flats Mar 16 '22 at 18:42

1 Answers1

1

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.

dnnshssm
  • 1,057
  • 6
  • 17
  • Hmm, it looks like the Grafana Version I have (6.6.2) does not have transformation capabilities. would you happen to know of any way that I could do this _without_ upgrading the version I am having to use? I understand that it may be my only option, but I'd like to avoid this if possible. – Flats Mar 15 '22 at 17:28
  • Well, that's quite an old version. Unfortunately I don't know about the possibilities back then. However, I'm sure you can accomplish what you want by using a query, but I can't help you with that since I don't use Influx. – dnnshssm Mar 16 '22 at 08:08
  • I do appreciate the answer, and if I must upgrade the version to do this, so be it. your suggestion seems that it would work though. Hopefully someone else can suggest an answer for older versions too. – Flats Mar 16 '22 at 16:15