InfluxDB: Flux - String comparison: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „''In this example I show you how to compare a tag [string] against another tag [string] in Flux.'' Example: <br> *We have to tags (VMName, vNICName) *We want…“) |
Admin (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
''In this example I show you how to compare a tag [string] against another tag [string] in Flux.'' | ''In this example I show you how to compare a tag [string] against another tag [string] in Flux.'' | ||
− | Example: <br> | + | '''Example:''' <br> |
*We have to tags (VMName, vNICName) | *We have to tags (VMName, vNICName) | ||
*We want to compare theses tags | *We want to compare theses tags | ||
*And show only rows that these tags not matched | *And show only rows that these tags not matched | ||
− | + | <pre> | |
import "strings" | import "strings" | ||
Zeile 29: | Zeile 29: | ||
})) | })) | ||
|> filter(fn: (r) => r.comparison != 0) // filter only cloned VMs | |> filter(fn: (r) => r.comparison != 0) // filter only cloned VMs | ||
− | + | |> keep(columns: ["_time", "VMName", "vNICName", "IsCloned"]) | |
+ | </pre> | ||
Version vom 8. Februar 2021, 11:39 Uhr
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
- And show only rows that these tags not matched
import "strings" from(bucket: "telegraf") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == "hyperv_vmnet" and r._field == "Bytes_Received_persec" and r.VMName !~ /TestRHE.*/ and //Exclude Test-VMs exists r.VMName //Exclude Hyper-V NICs ) |> last() |> group() //group to one table because "strings.compare" does not support multiple series // compare VMName and vNICName |> map(fn: (r) => ({r with comparison: strings.compare(v: r.VMName, t: r.vNICName) })) |> 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"])