Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change tag value in InfluxDB

Tags:

influxdb

I have data being inserted that uses host names. Annoyingly I'm about to change a domain from .lan to .mydomain.com

Obviously I'd like to be able to search my historical data of a machine as it crosses this change.

Can I update a tag definition from machine.lan to machine.mydomain.com?

like image 515
dcole Avatar asked Feb 01 '17 21:02

dcole


People also ask

What is tag key in InfluxDB?

The tag key location has two tag values: 1 and 2 . The tag key scientist also has two tag values: langstroth and perpetua . In the data above, the tag set is the different combinations of all the tag key-value pairs. The four tag sets in the sample data are: location = 1 , scientist = langstroth.

What is difference between tag and field in InfluxDB?

InfluxDB lets you specify fields and tags, both being key/value pairs where the difference is that tags are automatically indexed. Because fields are not being indexed at all, on every query where InfluxDB is asked to find a specified field, it needs to sequentially scan every value of the field column.

Is InfluxDB a key-value store?

InfluxDB as a key-value store As a cutting-edge time series database, InfluxDB borrows some ideas from key-value database designs. Earlier versions of InfluxDB actually provided support for RocksDB as a storage engine.


2 Answers

While @Michael's answer is correct in that you can't change tag values via InfluxDB commands, you can however write a client script that can change the value of a tag by inserting "duplicate" points in the measurement with the same timestamp, fieldset and tagset, except that the desired tag will have its value changed.

Point with wrong tag (in Line Protocol format):

cpu,hostname=machine.lan cpu=50 1514970123

After running

INSERT cpu,hostname=machine.mydomain.com cpu=50 1514970123

a SELECT * FROM CPU would include

cpu,hostname=machine.lan cpu=50 1514970123
cpu,hostname=machine.mydomain.com cpu=50 1514970123

After the script runs all the INSERT commands, you'll need to drop the obsolete series of points with the old tag value:

DROP SERIES FROM cpu WHERE hostname='machine.lan'

Of course, this is highly inefficient (note in particular this bug) and if you need to update a tag value to another tag value that other points you don't want to drop already have, you can't just DROP SERIES. So please vote for InfluxDB to implement tag renaming and in particular, changing tag values based on WHERE queries. Or consider an alternative time-series database that lets you use regular SQL, such as Timescale.

like image 154
Dan Dascalescu Avatar answered Sep 20 '22 18:09

Dan Dascalescu


Unfortunately, there isn't a way to change tag names for historical data in InfluxDB.

like image 23
Michael Desa Avatar answered Sep 19 '22 18:09

Michael Desa