I’m trying to draw a bar chart based on Series type X-Axis. The chart is based on Graph panel and is charting all the series it captures in the related time frame alright.
However, many of those series are relatively insignificant and I’d like to limit the series either by number or by a certain threshold, so that only the significant buckets will be presented.
I read through a bunch of threads here and on github but the main recommendation is to apply the top/limit filtering on the query side (In my case mySql).
Unfortunately, this recommendation doesn’t help cause it will just cut off the number or records returned from the DB arbitrarily when in fact we should return all the relevant records from the DB and perform the filtering only after Grafana performs its aggregation into the series.
Is it supported? Does it make sense?
Thanks!
Hi,
I’m afraid the recommendations you’ve read are correct. You have to solved this with the datasource you’re using.
Maybe you can do a group by followed by a having clause to filter out the insignificant metrics. I have never done this so not sure it will work, but should work in my head as long as you return data on the same format that the mysql datasource documentation explains.
Marcus
Thanks for your reply!
I’ll go ahead and implement it using group by over the SQL query, however, reading through a bunch of github posts I think it’s a feature worth considering:
Grafana serves a fundamental abstraction where it reduces the overhead of having to structure and adapt the queries to match the format of the graph, as Grafana sets the expected data structure while the panel developer takes the responsibility of adapting the data structure to the graph.
I think that applying group-by gymnastics slightly breaks this contract…
Anyway - Thanks again!
FWIW i’m pasting the group by query in case it might help others in the future:
select UNIX_TIMESTAMP(max(date)) as time_sec,
sum(VALUE) as value,
name as metric
from metrics_table
WHERE $__timeFilter(date)
group by name
order by value DESC
limit 5