Dynamically retrieve data from another bucket

I am trying to run a task that calculates status up and down percentages from a bucket ‘gantry’. I have defined the thresholds in another bucket ‘thresholds’ with static data. How can i retrieve the info from the ‘thresholds’ bucket and use it in my current task?

This is a snippet. Here, instead of hardcoding 60.0, I want to retrieve it from the _value column from the thresholds bucket. Is it possible in InfluxDB?

gw_combined_uptime
|> map(
fn: (r) =>
({
_time: now(),
_measurement: “pg_status”,
_field: “uptime_percentage”,
facility: “Gateway”,
Metric_area: “Mechatronics”,
parent_grouping: “Gantry_System”,
status: if r._value >= 60.0 then “up” else “down”,
_value: if not exists r._value or r._value == 0 then 0.0 else r._value,
}),
)
}

@farmurey Yep, definitely possible. You can query the other bucket and extract the value as a scalar value and assign it to a variable. Something like this:

uptime_threshold = (from(bucket: "example-bucket")
    |> range(start: -1d)
    |> filter(fn: (r) => r._measurement == "example-measurement")
    |> last()
    |> findRecord(fn: (key) => true, idx: 0)
)._value

gw_combined_uptime
    |> map(
        fn: (r) =>
            ({
                _time: now(),
                _measurement: "pg_status",
                _field: "uptime_percentage",
                facility: "Gateway",
                Metric_area: "Mechatronics",
                parent_grouping: "Gantry_System",
                status: if r._value >= uptime_threshold then "up" else "down",
                _value: if not exists r._value or r._value == 0 then 0.0 else r._value,
            }),
        )
    }

Thank you so much, this worked for me.

1 Like