我正在编写一个简短的Python脚本,允许用户更改标记上保留的长度。用户输入他们想要查看的度量,然后在提示可能的“标识符”后,输入他们想要更改的度量,然后输入持续时间。看起来是这样的:
from influxdb import InfluxDBClient
import os, pdb
client = InfluxDBClient('localhost', 8086, database='JSON_DATA')
print('\nEnter the Measurement, you want to access: ')
measurement = str(input())
uIds = []
ids = client.query("SHOW TAG VALUES FROM " + measurement + " WITH key = Identifier;")
print('\nAvailable Identifiers:')
for i in ids:
for j in i:
uIds.append(j['value'])
print(j['value'])
print('\nEnter the Identifier you want to alter: ')
Id = str(input())
retry = True
while retry:
if Id not in uIds:
print('\nNot a valid Identifier, please retry:')
Id = str(input())
else:
retry = False
print('\nWhat Retention Policy are you applying to' , Id ,':')
print('Current policies:')
uRps = []
Rps = client.get_list_retention_policies(database='JSON_DATA')
for i in Rps:
uRps.append(i['name'])
print('\t'+i['name'])
print('\nOr create your own by entering desired time')
print('24h = 24 hours, 3d = 3 days, 52w = 52 weeks/1 Year')
print('m for Months and y for Years is not compatible')
newRP = str(input())
if newRP in uRps:
result = client.query("SELECT * INTO \"" + newRP +"\".\"" + measurement + "\" FROM " + measurement + " WHERE Identifier = \'" + Id + "\';")
print(result)
elif newRP not in uRps:
client.create_retention_policy(newRP, newRP, 1, database=JSON_DATA, default=False)
result = client.query("SELECT * INTO \"" + newRP +"\".\"" + measurement + "\" FROM " + measurement + " WHERE Identifier = " + Id + ";")
脚本检查用户输入的持续时间是否与现有的保留策略相同,如果不相同,则创建一个新的保留策略。
我的问题有两个方面:
1我真的很难找到任何关于RPs的深入文档,但在一个涌入社区的帖子中,我发现了以下问题:
SELECT * INTO <new_RP>.<measurement_name> FROM <old_RP>.<measurement_name> WHERE <tage_key> = '<tag_name>'
所以我试着在一个示例数据库上验证它的有效性
> show retention policies
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
1_hour 1h0m0s 1h0m0s 1 false
> select * into "1_hour"."h2o_quality" from h2o_quality where location='coyote_creek' and randtag='1'
name: result'
time written
---- -------
1970-01-01T00:00:00Z 0
有人知道输出“writed”在这里是什么意思吗?如果这意味着没有数据的RP被修改,那么我猜要么是我输入的查询错误,要么是它不起作用
2在运行我的脚本后,我得到了这个错误
Traceback (most recent call last):
File "influxScript.py", line 44, in <module>
result = client.query("SELECT * INTO \"" + newRP +"\".\"" + measurement + "\" FROM " + measurement + " WHERE Identifier = \'" + Id + "\';")
File "C:\Users\user\Documents\Database\env\lib\site-packages\influxdb\client.py", line 461, in query
in data.get('results', [])
File "C:\Users\user\Documents\Database\env\lib\site-packages\influxdb\client.py", line 460, in <listcomp>
for result
File "C:\Users\user\Documents\Database\env\lib\site-packages\influxdb\resultset.py", line 25, in __init__
raise InfluxDBClientError(self.error)
influxdb.exceptions.InfluxDBClientError: partial write: points beyond retention policy dropped=7294
有人知道partial write: points beyond retention policy dropped=7294
是什么意思吗?我想这可能是因为我输入的保留策略比数据的时间戳早/短,但我不知道会是这样
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐