在InfluxDB中更改标签值 [英] Change tag value in InfluxDB

查看:784
本文介绍了在InfluxDB中更改标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在插入使用主机名的数据.烦人的是,我要将域名从.lan更改为.mydomain.com

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.

我可以将标记定义从machine.lan更新为machine.mydomain.com吗?

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

推荐答案

@Michael的答案是正确的,因为您无法通过InfluxDB命令更改标签值,但是您可以编写一个客户端脚本来更改afluxDB的值.通过在测量中插入重复" 点来进行标记时间戳,字段集和标签集,只是所需标签的值会更改.

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

运行后

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

SELECT * FROM CPU将包括

a SELECT * FROM CPU would include

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

脚本运行所有INSERT命令后,您需要删除带有旧标记值的过时点系列:

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'

当然,这是非常低效的(请特别注意此错误),以及是否需要将标签值更新为另一个您指向的标签值不想删除已经拥有的,则不能只是DROP SERIES.因此,请投票给InfluxDB实施标签重命名,尤其是根据WHERE查询.或考虑使用其他时间序列数据库,使您可以使用常规SQL,例如 Timescale .

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.

这篇关于在InfluxDB中更改标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆