InfluxDB: Flux - String comparison
Aus Wiki-WebPerfect
Version vom 8. Februar 2021, 14:09 Uhr von Admin (Diskussion | Beiträge)
In this example I show you how to compare a tag [string] against another tag [string] in Flux.
Example:
- We have to tags (VMName, vNICName)
- We want to compare theses tags -> strings.compare(v: r.<tag1>, t: r.<tag2>)
- And show only rows that these tags not matched
import "strings" from(bucket: "<YOUR_BUCKET>") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == "hyperv_vmnet" and r._field == "Bytes_Received_persec" and exists r.VMName //Exclude Hyper-V NICs ) |> last() |> group() //group to one table because "strings.compare" does not support multiple series // convert strings to upper for comparison |> map(fn: (r) => ({r with toUpperVM: strings.toUpper(v: r.VMName), toUpperNIC: strings.toUpper(v: r.vNICName) })) // compare VMName and vNICName |> map(fn: (r) => ({r with comparison: strings.compare(v: r.toUpperVM, t: r.toUpperNIC) })) |> map(fn: (r) => ({r with IsCloned: if r.comparison == 0 then "not cloned" else "yes" })) |> filter(fn: (r) => r.comparison != 0) // filter only cloned VMs |> keep(columns: ["_time", "VMName", "vNICName", "IsCloned"])