Change tag value in InfluxDB

試著忘記壹切 提交于 2019-11-30 02:03:55

问题


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?


回答1:


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.




回答2:


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




回答3:


There is already an open feature request on GitHub for this. https://github.com/influxdata/influxdb/issues/4157

A probable solution suggested by influx developer if you want to go down the dump all, modify, re-import path (brutal, but effective), this comment might help.

https://github.com/influxdata/influxdb/issues/3904#issuecomment-268918613



来源:https://stackoverflow.com/questions/41990346/change-tag-value-in-influxdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!