Best way to visualize number of distinct tags over time?

Hello All,

I have a network of sensors passing data to influxdb. Each sensor has a unique ID, used as a tag in Influx.

Updated for clarity
I have one tag key defined (confusingly called “tag”) and each sensor ID is a tag value.

Here’s some sample data that shows the structure:

time - - - - - - - - - - - - - - Battery ValueA ValueB ValueC tag

1608896450000000000 90 38.62 60 101.19 00C5
1608896451000000000 90 39.35 62 101.19 00C6
1608896451000000000 90 38.62 11 102.13 00C5
1608896451000000000 90 41.15 37 101.28 00Cb

If I’ve understood the terminology properly, the sensor IDs are tag values and the rest are measurements.

Let’s say we start with 100 sensors (and therefore 100 different tags). Over time, some sensors get damaged, unplugged or otherwise incapacitated.

I have three related questions:

  1. What is the best query to use to determine the number of distinct tags in a database?
  2. Is is possible to query the number of tags that have reported data within a given time range?
  3. Is it possible to create a chart in Grafana that shows how many distinct tags are reporting data over time?

All suggestions welcome.

Hello @NickN,
Are you using 1.x or 2.0?
First I’d like to recommend against making a tag with unbounded values a tag, that should be a field instead. Things sensor ID, customer ID, etc are typically made fields to reduce cardinality and avoid runaway cardinality.

If you’re using 2.0, I recommend using the operation monitoring template to track your cardinality.

Hi @Anaisdg

I’m using 1.8 as it’s running on 32-bit Raspbian OS.

I’m curious, and forgive me if this is an utterly noob question, but what is a good example use case for tags?

Sensor ID seemed to make sense as we often want to search on everything from a specific sensor, but I may well have misunderstood.

Thanks for your help!

Hello @NickN,
SensorID can be a tag if it’s scoped. However, if you’re planning to grow your sensors indefinitely, then making sensorID a tag might result in runaway series cardinality.

No problem, that’s what we’re here for. Does that help?