3

我正在编写一个简短的 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 的任何深入文档,但是在 influx 社区帖子中我发现了这个查询: 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意思?我在想这可能是因为我输入的保留政策比数据的时间戳更早/更短,但我不知道是这种情况谢谢

4

0 回答 0