Infinity plugin + JSON + dashboard variables

I’m running Grafana on a Linux OS

The goal is to use a JSON to pass data to a variable.
This variable will be used to modify (filter, visualisation name, timerange, …) a dynamic dashboard.

The variable is created on the dasboardsettings as ‘query’, and is named “testvar”.
I have the following example data, as inline data for the infinity datasource

[
        {
            "entity":"GOOGL",
            "price": 2155.85,
            "time": 1653603843766
        },
        {
            "entity":"AAPL",
            "price": 143.78,
            "time":1653603943766
        }
    ]

In parsing options, I have defined the columns:
entity, price, time.
On the dashboard I want to (for example) visualize the value of the entity.
This works as I enter ${testvar}, “GOOGL” or “AAPL” is returned depending on the selection in the dashboard.
However I also want to visualize the price and time.
I’ve tried ${testvar:price} but this only works when there are 2 columns defined.
When I define a third column, everything returns the same value, no matter what I try.

Bottom line: I want to have a dropdown box that is populated with the “entity” of the json, and use the referencing data “price” and “time” in the dashboard.
for example: ${testvar.price} and ${testvar.time}

Kind regards

Hi,

I’m not master of Infinity Plugin, so it might be not the best answer, but I think what is happening is that Grafana allows you to have key:value pairs as your variable (see this link). As I’ve noticed, if you pass ${var:<whatever>} you’ll get the value of your query, so that’s why it worked with one value and not with three columns.

What you can do is to use a couple of variables. The first one being the list of values of entity fields - let’s call it type variable.


Then you could create another variable (let’s call it price) where you paste your data, select entity and price columns. In Filter option, you pass contains("${type}", entity), which will limit the possible values of your the data only to the ones containing the type variable. In result, you’ll have just one variable which corresponds to the price of the entity you select in your type variable.

You repeat this step for another variable time (which you do analogously to the price variable only changing the column from price to time). You can hide price and time variables. In your visualizations, you’ll use variables price and time wherever you wanted to use testvar.price and testvar.time but your end user will see only one variable to rule them all.

Disadvantages are that you have to create multiple variables and use them, even though they are not presented on the dashboard, but I don’t know better way to do this (and my knowledge says it might be impossible to do it the way you wanted with 3 columns in one variable).

1 Like

Tried the above, but I couldn’t get a consistent solution.
Sometimes I get the error ‘unsupported data format’ when creating the variable.

Strange thing, because I can’t figure out why since everyting is the same for each variable.
Also the JSON I’ve provided are all strings.

so you can only have 2 data points. which one can you live without?

you can choose uql then do this as an example

parse-json
| extend "__value"="entity", "__text"="price"

with this text will be displayed, price would be the value for selected item

With the combination of the answers from @solitcon and @dawiddebowski provided above I was able to figure out the solution.

Note: I used a different dataset for this example. It’s still JSON, but the field names differ from my starting post.

[
  {
    "friendly_name": "Meting 1",
    "channel": "ch01",
    "current": "6",
    "starttime": "9",
    "stoptime": "17"
  },
  {
    "friendly_name": "Meting 2",
    "channel": "ch02",
    "current": "10",
    "starttime": "9",
    "stoptime": "17"
  }
]

The following dashboard variables are created:
image

First I created the variable that functions as the ‘master selector’ (type ‘Query’).
This is the only one that is visible on the dashboard.
For query options I used the following configuration:


This propagates a list with friendly names from which I can select, that hold a less readable value.
This ‘value’ I use in further variable queries.

Second (this applies to all the other variables) I created variables that change depending on the first ‘master’ variable. These are also of type ‘Query’.
For query options I used the following configuration:


Notice the ‘WHERE’ clause: this filters the returned values depending on the value of the ‘master’ variable (varMeting). The ‘:raw’ is to select only the value, and not the diplay name ()

parse-json
| where "channel" in (${varMeting:raw})
| extend "__value"="current"

I’ve repeated this proces for all the other variables I needed.
Only changing the last line of UQL: in which I replace ‘current’ with the property I need.

| extend "__value"="current"
3 Likes

nice! also look into using the Business Variable plugin for nice layout instead of ugly drop downs

image