How to get Series Name with Alert?

Although reading concepts of alerting I’m still not able to find a solution. Next I had a nice chat with the Grafana bot, but did not find a solution with its support. Hope with your experience there will be a solution finally…

Actually I’m fighting with alerts. Basically alerts getting sent out, but only contain cryptic information on the series (in my case a battery operated device) raising the threshold. Text is like Value: B=16. I assume B=16 shall refer to series number 16 which is causing the alert. Well, but please give me the series name instead of the numeric index.

Image below shows my current setup. A query based on time series data in influx DB. To get each sensor, I use a regex pattern, matching to all series ending on battery. For each, only last value is of interest and shall be compared against the threshold.

All this works pretty well, new sensors will be automatically covered given by the regex approach. But side effect from this dynamic query is that I need to grab the name of the respective series, here #16.

How to do this?

1 Like

Good morning, as there is no feedback yet, maybe my question was not that specific. Let me summarize:

  • Influx data source provides battery state for bunch of sensors
  • In a dashboard, last battery value per sensor is shown
  • To catch all sensors, I do not use independent query each, but a regex based multi series query instead
  • Based on dashboard, an alert rule fires and tells me that any of my sensors is running out of battery
  • Alert does not contain sensor name (which is the series in the dashboard)

May anyone having more experience than me please guide me on how to put the name of each series to the query, so that it may be shown in alert message?

I assume need to somehow convert series into label, but no clue how to. This is my based query in section A, you see the regex approach to cover all sensors there. But how to get name for each of these multi series (which will be sensor1, sensor2, …) as dedciated label-column appearing in the result?

SELECT last("value") FROM /^alias.0.*.battery/ WHERE $timeFilter GROUP BY time($interval)

Thanks for your kind support!

You query must return that value in the result. It looks like you are not following best practices, so you will have problem with that now.

Keep names free of data.

Use one measurement for all devices, where you will have device tag, e. g. measurement devices, tag device, field value. You will be grouping also by device tag in your alert query and then it will be available as label for the alert message.

Thank you for your feedback :wink:

Actually, I use influx:1.8 running in docker container on a 32bit Raspberry PI. The influx DB is accessed from ioBroker via adapter. Inside this adapter and with dependency to influx:1.* there is no chance to apply tags.

Following your recommendation, I will have to reinstall Raspberry PI with 64Bit OS. Next install influx:2.* (which is not available for 32bit) so that I may publish tags from ioBroker. Right, this is an option, but lot of work :flushed:

Are there any other options, to stick with influx:1.8 (not instantly getting single series, attributed by tags) but somehow turn series names into something like tags? Probably some subquery structure, transforming my data so that I will get series name as label, value and timestamp?

No, this is not about InfluxDB version (so you don’t need to upgrade your InfluxDB version). Problem is your data structure, which is not following best practices - you keep data (e.g. location name in this particular case) in the measurement name :cold_sweat:.

Sure, I got your point, thanks :pray:

But in my current infrastructure (ioBroker writing data into Influx:1.8 DB via adapter) I can’t control the data structure. It will be just written as is, like:

  • Full sensor name (in my case including the location) as series
  • Numeric value (battery level in percent)
  • Timestamp per observation

So yes, you’re right, if I just would change structure of data this would make things much more easy in Grafana. But without major changes I will not be able to manage/control structure of data.

There’s another hint on this. Reads very close to your feedback, but in fact results in need to complete change my runtime environment (upgrade of PI to go via 64bit OS). Have to think about that, maybe this 32->64bit upgrade will make sense from other perspective as well.

Finally, reads like in my environment (given by the fix data structure in influx) I will never achieve my requirement, which is to have the series name (=sensor in my case) appearing in the alert, right?

OK, so in that case you have non ideal data structure, but you can still achieve your goal.
Of course also not in optimal way in the Grafana. Just create alert for each device (so no regexp in measurement name) and hardcode device label in alert labels section. It should work.
Yes, that means if you have million devices, then you have to create million alerts (instead of just one, which can be used when you have optimal data structure) - that will be price, which you have to pay.