Tree Map Panel: group by using two numeric fields

I am working on Grafana 11.2.2.

I am building a treemap panel where I have to show no of slot hrs( sum of slot hrs) and avg wait time by cores and product.

So I understand Treemap needs a string and Number.

While my Product is String and Cores requested which is (req_mem_min) is a numeric field.

I gave a lucene query with the filters and metrics as sum of slot hrs and avg of wait time and group by product and then by two types of numerics fields.

do we have an option of using two numeric fields( one which has minimum no of cores requested by the job and the other one is max number of cores requested) in grafana tree map panel.

Hello @veenanallapaneni,

I’ve implemented the solution using a PostgreSQL data source.

Step 1. Create table and insert dummy data


CREATE TABLE job_stats (
    job_id SERIAL PRIMARY KEY,
    product VARCHAR(50),
    req_mem_min INT,
    req_mem_max INT,
    slot_hrs NUMERIC,
    wait_time NUMERIC
);

INSERT INTO job_stats (product, req_mem_min, req_mem_max, slot_hrs, wait_time) VALUES
('ProductA', 4, 8, 10.5, 30),
('ProductA', 4, 8, 12.0, 25),
('ProductA', 8, 16, 8.0, 35),
('ProductB', 2, 4, 15.0, 20),
('ProductB', 2, 4, 14.0, 22),
('ProductC', 16, 32, 5.0, 40),
('ProductC', 16, 32, 6.5, 38);

Step 2. Integrate Tree Map Visualization

Step. 3 Panel Query

SELECT
product,
req_mem_min || ‘-’ || req_mem_max AS core_range,
SUM(slot_hrs) AS total_slot_hrs,
AVG(wait_time) AS avg_wait_time
FROM job_stats
GROUP BY product, req_mem_min, req_mem_max;

Final Result

Hi @veenanallapaneni ,
Just checking in—did this solution resolve your issue, or are you still facing the same problem?

Hi @infofcc3

Thank you so much for responding to my question.

Appreciate the follow-up!

I am using elastic as data source and I tried grouping by req_mem_min and req_num_procs_min.

It is not working when I give group by two numeric fields.

When I delete one of it then it is working.

Is there a way to group by two numeric fields using lucene query.

Thank you once again for the response.

1 Like

Hi @veenanallapaneni,

There isn’t a direct method to group the values, but you can achieve this using aggregations. You may find the following documentation helpful:

@infofcc3

Thank you so much!I will go through and try to get a solution.
will keep you posted.

1 Like

Welcome :star_struck: @veenanallapaneni