grafanainfluxdbhyper-vtelegraf

How can i convert influxql to flux


I want convert influxql to flux.

SELECT mean("Percent_User_Time") AS "% User Time" 
FROM "win_cpu" WHERE "host" =~ /^$hostname$/
AND $timeFilter 
GROUP BY time($__interval) fill(linear)"

I tried below...that is not work

   from(bucket: "your-bucket-name")
  |> range(start : -10m)
  |> filter(fn: (r) => r["_measurement"] == "win_cpu" and r["_field"] == "Percent_User_Time" and r["host"] =~ /^$hostname$/)
  |> aggregateWindow(every: $__interval, fn: mean, createEmpty: false)
  |> yield(name: "% User Time")

how can make work flux?

I want work flux like influxql.


Solution

  • To use linear interpolation in Flux you may use interpolate.linear function from interpolate package. Try something like this:

    import "interpolate"
    
    from(bucket: "my-bucket-name")
      |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
      |> filter(fn: (r) => r._measurement == "win_cpu" and r._field == "Percent_User_Time" and r.host =~ /^${hostname}$/)
      |> aggregateWindow(every: ${__interval}, fn: mean, createEmpty: false)
      |> interpolate.linear(every: ${__interval})
      |> set(key: "_field", value: "% User Time")