influxdb v3 query merged tables return no result

27 views Asked by At

i using influx db query to return metrics i merged three table result in one by wirting three query and use join() for merge but if one of this queries return no result then merged table return no result i need to return other queries data

this my query disk and memory return data but cpu return no result if i merged cpu with disk and memory then merged table returned as no result this is my query

i using influx db query to return metrics i merged three table result in one by wirting three query and use join() for merge but if one of this queries return no result then merged table return no result i need to return other queries data and this is my query

type here

    //Define your queries for different measurements
    memory=from(bucket: "telegraf")
   |> range(start : -2d)
   | > filter(fn: (r) => r["_measurement"] == "mem")
   |> filter(fn: (r) => r["_field"] == "used")
   |> filter(fn: (r) => r["host"] == "host")
   |> limit(n:20)    
   |> map(fn:(r) => ({r with "_value" : string(v: r["_value"])}))
   |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
   |> group()
    |> sort(columns: ["_time"], desc: false)

    disk=from(bucket: "telegraf")
   |> range(start : -2d)
   |> filter(fn: (r) => r["_measurement"] == "disk")
   | > filter(fn: (r) => r["_field"] == "used")
   |>  filter(fn: (r) => r["host"] == "host")
   |> limit(n:20)    
   |> map(fn:(r) => ({r with "_value" : string(v: r["_value"])}))
   |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
   |> group()
   |> sort(columns: ["_time"], desc: false)

    cpu=from(bucket: "telegraf")
   |> range(start : -2d)
   |> filter(fn: (r) => r["_measurement"] == "cpu")
   |> filter(fn: (r) => r["_field"] == "usage_idle")
   |> filter(fn: (r) => r["host"] == "host")
   |> limit(n:20)    
   |> map(fn:(r) => ({r with "_value": float(v: r["_value"])}))
   |> map(fn: (r) => ({ r with _value: 100.0 - r._value }))
   |> map(fn:(r) => ({r with "_value" : string(v: r["_value"])}))
   |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
   |> group()
   |> sort(columns: ["_time"], desc: false)

    result=join(tables:{memory:memory, disk:disk}, on:["_time"])
    join(tables: {result: result,cpu: cpu}, on:["_time"])
    |>yield()


1

There are 1 answers

0
khaled On
i solved this by using replace join by union and doing pivot in last result 
 as 
    memory=from(bucket: "telegraf")
    |> range(start:-2d)
    |> filter(fn: (r) => r["_measurement"] == "mem")
    |> filter(fn: (r) => r["_field"] == "used")
    |> filter(fn: (r) => r["host"] == "host_id}")
    |> limit(n:10)    
    |> map(fn:(r) => ({r with "_value" : string(v: r["_value"])}))
    |> group()

    cpu=
    from(bucket: "telegraf")
    |> range(start:-2d)
    |> filter(fn: (r) => r["_measurement"] == "cpu")
    |> filter(fn: (r) => r["_field"] == "usage_idle")
    |> filter(fn: (r) => r["host"] == "${host_id}")
    |> limit(n:10)
    |> map(fn:(r) => ({r with "_value": float(v: r["_value"])}))
    |> map(fn: (r) => ({ r with _value: 100.0 - r._value }))
    |> map(fn:(r) => ({r with "_value" : string(v: r["_value"])}))
    |> group()

   disk = from(bucket: "telegraf")
    |> range(start:-2d)
    |> filter(fn: (r) => r["_measurement"] == "disk")
    |> filter(fn: (r) => r["_field"] == "used")
    |> filter(fn: (r) => r["host"] == "${host_id}")
    |> limit(n:10)
    |> map(fn: (r) => ({ r with _value: string(v: r._value) }))
    |> group()

     union(tables: [memory, disk, cpu])
    |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn:  
        "_value")
    |> group()
    |> sort(columns: ["_time"], desc: false)