Create bar gauge to count string fields

Using Grafana Cloud with InfluxDB, I want a bar gauge showing a count of how many devices are running each firmware version. The data comes from Telegraf. Here’s a simplified example in line format for one device:

qsys_core_info,name=QSYS001,source= version="9.8.2-2308.002" 1707874158000000000

With Prometheus, I can get the result I want using query: count by(version) (qsys_core_info). How can I do this in InfluxQL?

In this example there are 4 devices total.

What have you tried so far? And what happened to what you tried?

Did you try your question in influxdn community forum?

Hi @llamafilm

Can you share some sample data as you have it currently stored in InfluxDB, and state which items are fields and which are tags? I believe you must have version defined as a tag, and then your query would include GROUP BY version (which is only possible is version is a tag).

Version is currently a field. Sorry, I thought that was clear from the line protocol example. What format would be helpful to show the sample data?

CSV should be fine and remember to state which items are fields and which are tags.

Given what I wrote earlier, can you change it so Version is a tag? How many unique versions could their theoretically be? (just trying to understand if cardinality is a potential issue)

Yes, that would be possible to change in Telegraf, if that’s the only option. That’s how I got it working in Prometheus (as a label).

But since Influx supports string type fields, I wanted to try it out and see if it makes more sense here. The number of versions is about 10, but I think the cardinality would be significant as it multiplies by many other tags. (I redacted some of the other tags here for brevity.)

ingested your data with some mock fake stuff

import pandas as pd
from influxdb_client import InfluxDBClient, 
Point, WritePrecision, WriteOptions
from influxdb_client.client.write_api import SYNCHRONOUS
from datetime import datetime

from dotenv import load_dotenv
import os

TOKEN = os.getenv('TOKEN')
URL = os.getenv('URL')
ORG = os.getenv('ORG')

bucket = "llama"

Write data into InfluxDB
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
write_api = client.write_api(write_options=SYNCHRONOUS)  

for next_ip in range(10):
    point = Point("llama") \
            .measurement("qsys_core_info") \
            .tag("name", "QSYS002") \
            .field("source", "" + str(next_ip)) \
            .field("version", "9.8.2-2308.00" + str(next_ip)) \
            .time(datetime.utcnow(), WritePrecision.NS)

    write_api.write(bucket, ORG, point) 

Close client