【问题标题】:InfluxDBClientError: retention policy not found: autogenInfluxDBClientError:未找到保留策略:autogen
【发布时间】:2018-12-11 16:04:09
【问题描述】:

我正在通过https://www.influxdata.com/blog/getting-started-python-influxdb/ 文档使用python查询influxdb。

我能够创建数据库:

client = InfluxDBClient(host='localhost', port=8086)
client.create_database('pyexample')
client.get_list_database() 
client.switch_database('pyexample')

另外我也在数据库内部发送数据:

json_body = [
{
    "measurement": "brushEvents",
    "tags": {
        "user": "Carol",
        "brushId": "6c89f539-71c6-490d-a28d-6c5d84c0ee2f"
    },
    "time": "2018-03-28T8:01:00Z",
    "fields": {
        "duration": 127
    }
},
{
    "measurement": "brushEvents",
    "tags": {
        "user": "Carol",
        "brushId": "6c89f539-71c6-490d-a28d-6c5d84c0ee2f"
    },
    "time": "2018-03-29T8:04:00Z",
    "fields": {
        "duration": 132
    }
},
{
    "measurement": "brushEvents",
    "tags": {
        "user": "Carol",
        "brushId": "6c89f539-71c6-490d-a28d-6c5d84c0ee2f"
    },
    "time": "2018-03-30T8:02:00Z",
    "fields": {
        "duration": 129
    }
}
]

调用 json 主体为:

client.write_points(json_body)
True 

但现在很快,我想通过以下方式从数据库中查询指标:

client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

此查询导致错误:

文件 ipython-input-31-6e47204db16b,第 1 行,在模块中 client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py”,第 420 行,查询中 在 data.get('结果', [])

init 中的文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/resultset.py”,第 25 行 引发 InfluxDBClientError(self.error)

InfluxDBClientError: retention policy not found: autogen

如何获取查询结果?

我检查了保留政策,也发现了错误:

client.query('SHOW RETENTION POLICIES')

Traceback(最近一次调用最后一次):

文件“”,第 1 行,在 client.query('显示保留政策')

文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py”,第 409 行,查询中 expected_response_code=expected_response_code

文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py”,第 286 行,在请求中 引发 InfluxDBClientError(response.content, response.status_code)

InfluxDBClientError: 400: {"error":"error parsing query: found EOF, expected ON at line 1, char 25"}

【问题讨论】:

  • 如果你执行client.query('SHOW RETENTION POLICIES')会得到什么?
  • @Stanko 我在问题主体中也添加了由命令client.query('SHOW RETENTION POLICIES') 生成的错误。请看一下
  • 该错误表明您需要指定要在其上执行查询的数据库。试试看:client.query('SHOW RETENTION POLICIES ON pyexample')
  • client.query('SHOW RETENTION POLICIES ON pyexample') 工作并给出以下输出ResultSet({'(u'results', None)': [{u'duration': u'0', u'default': True, u'replicaN': 1, u'name': u'default'}]}) 现在如何修改我的数据库查询?
  • default 替换autogen 应该可以解决问题。

标签: influxdb-python


【解决方案1】:

autogen 更改为default

client.query('SELECT "duration" FROM "pyexample"."default"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

【讨论】:

  • 奇怪...它将Out[5]: ResultSet({}) 作为输出。输出如何为空。我们在这里错过了@Stanko
  • 很高兴您没有收到表示保留策略“默认”已找到的错误,因此您的第一个问题已解决。由于您的 WHERE 条件,您没有得到任何结果。查看数据的时间戳,它们的范围从 2018-03-28 到 2018-03-30。在您的WHERE 条件中,您希望显示时间在 4 天前 (time > now() - 4d) 之后的数据点。运行不带WHERE 的查询:client.query('SELECT "duration" FROM "pyexample"."default"."brushEvents" GROUP BY "user"')。这应该会给你按用户分组的 3 个点。
  • 是的,查询有效,感谢您解释保留政策概念。我明白了。 :) @Stanko
  • 没问题,很高兴它有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-08
  • 2019-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多