我正在编写一个简短的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.我真的很难找到有关RP的任何深入文档,但是在大量社区帖子中,我发现了以下查询:
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
有人知道输出“写”在这里意味着什么吗?如果这意味着没有数据比他们的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
是什么意思吗?我当时想这可能是因为我输入的保留政策比数据的时间戳短/短,但我不知道这种情况
谢谢