0

I have some data in influxdb with a failure field key that is a bunch of names separated by commas (not a set amount of data). I would like to make a new row in grafana for each of those names. Right now, I am just using a new entry in influxdb for each name, but that creates a whole ton of data points in influx. So I was hoping to just have one data point with multiple names.

First off, is there a way to do this in grafana? As far as I have been able to see, there is not.

So I am trying to use flux. The following query works to get the data point I need from influx, and it displays the data with each field and tag a separate column, but the field failure just has the csv in it.

from(bucket:"testbucket")
  |> range(start: -7d)
  |> filter(fn: (r) => r._measurement == "care_stigs" and r.device_name == "Paul")
  |> pivot(
        rowKey:["_time", "_measurement"],
        columnKey: ["_field"],
        valueColumn: "_value"
      )

I have tried multiple things including things from the following post:

How to split a string column in two in Flux (InfluxDB)

The following gives me an error invalid: error @16:22-20:13: found unexpected argument failure (Expected r) (argument fn) error @16:22-20:13: missing required argument r (argument fn) error @14:6-21:8: expected stream[string] but found [string] (array) (argument tables)

import "strings"

from(bucket:"testbucket")
  |> range(start: -7d)
  |> filter(fn: (r) => r._measurement == "care_stigs" and r.device_name == "Paul")
  |> pivot(
        rowKey:["_time", "_measurement"],
        columnKey: ["_field"],
        valueColumn: "_value"
      )
  |> map(fn: (r) => ({
        parts: strings.split(v: r.failed, t: ",")
      }))
  |> map(fn: (r) =>
        r.parts
          |> map(fn: (failure) => ({
              first: failure[0],
              second: failure[1],
              third: failure[2]
          }))
      )

The closest I have got is to do

import "strings" 
from(bucket:"testbucket")
  |> range(start: -7d)
  |> filter(fn: (r) => r._measurement == "care_stigs" and r.device_name == "Paul")
  |> pivot(
        rowKey:["_time", "_measurement"],
        columnKey: ["_field"],
        valueColumn: "_value"
      )
  |> map(fn: (r) => ({
        "time": r._time,
        "measurement": r._measurement,
        "device": r.device,
        "failed": strings.split(v: r.failed, t: ",")
      }))

but that gives me the following error (which I understand): invalid: runtime error @11:6-16:10: map: map object property "failed" is array type which is not supported in a flux table

How do I turn those parts into rows? And especially not knowing the exact number of rows? (by the way, if it helps, I only need one data point per query - but I want a table out of that one data point with the rows being the comma separated values)

AeroByte
  • 1
  • 2

0 Answers0