Is it possible to fetch legend value(like max) for some other external use?

as we know, there are variables like $col, are there similar variable for legend max? if no, we need to do a another query to poll the max, that’s wast of resource, especially for huge data.
The requirement I got it to draw a threshold line as Max * percent(customer defined variable).

I played with transform,but still got no luck.

What is your datasource

influxdb.

are you using flux or influxql query language?
please provide some sample data. this will help us emulate your data in our influxdb to best help you

original influxdb stores 1 minute interval data.

With query like this to get time series:

select percentile(“bps”, $percent1) as “bps” from (
SELECT sum(“value”) as “bps” FROM “portTraffic” WHERE ( ${complexCondition} ) AND metric= ‘TxBps’ AND $timeFilter GROUP BY time(1m) fill(null)
) GROUP BY time($__interval)

now we need add horizential threshold line like max_of_query_result*$threadPercent.

If we can get max_of_query_result from legend max value, everything is easy.
if not, I need do another query to get max_of_query_result like this:
select max(“bps”) as “max” from (
select percentile(“bps”, $percent1) as “bps” from (
SELECT sum(“value”) as “bps” FROM “portTraffic” WHERE ( ${complexCondition} ) AND metric= ‘TxBps’ AND $timeFilter GROUP BY time(1m) fill(null)
) GROUP BY time($__interval)
)
Since we have multiple years data, it takes time to query even once. I really do not want to query twice.
My question is that the max of query result(time series) is already there in legend/max. How can we fetch and use it?
influxdb version is 1.8. it support flux, but I feel that flux is slower(I may be wrong, since I do not use flux that much).
Thanks in advance.

that looks like queries but not sample data.

time host interface metric value


2024-03-19T19:02:00Z hostA 1/1/25 TxBps 44645100
2024-03-19T19:02:00Z hostB 2/1/25 TxBps 53468200
2024-03-19T19:02:00Z hostC 3/1/25 TxBps 38762600
2024-03-19T19:03:00Z hostA 1/1/25 TxBps 44645200
2024-03-19T19:03:00Z hostB 2/1/25 TxBps 53468300
2024-03-19T19:03:00Z hostC 3/1/25 TxBps 38762700
2024-03-19T19:04:00Z hostA 1/1/25 TxBps 44645300
2024-03-19T19:04:00Z hostB 2/1/25 TxBps 53468400
2024-03-19T19:04:00Z hostC 3/1/68 TxBps 38762800

select percentile(“bps”, $percent1) as “bps” from (
SELECT sum(“value”) as “bps” FROM “portTraffic” WHERE ( (host=‘hostA’ and interface=‘1/1/25’) or (host=‘hostB’ and interface=‘2/1/25’) or ( host=‘hostC’ and interface=‘3/1/25’ ) ) AND metric= ‘TxBps’ AND time>now()-730d GROUP BY time(1m) fill(null)
) GROUP BY time($__interval)

if I use flux,

  1. first, get time series like this:

timeseriesresult =from(bucket: “<bucket_name>”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)

|> yield()
this will display the time series in the chart.
2. then I can get max directly,
timeseriesmax = timeseriesresult
|>max()
now the question is : how to use this timeseriesmax result outside of this flux query?

I think I got it:

  1. add expression:

  2. use transform:

  3. enable the threshold.
    Now it works.

1 Like