我正在阅读https://www.influxdata.com/blog/getting-started-python-influxdb/文档,用python查询进水数据库。
我能够创建数据库:
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"')此查询将导致错误:
Client.query模块中的文件ipython 31-6e47204db16b,第1行(从“py示例”.“autogen”.“brushEvents”中选择“持续时间”,其中time > now() - 4d按“用户”分组) 文件"/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py",第420行,在data.get中查询(“结果”,[]) 文件"/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/resultset.py",第25行,在init InfluxDBClientError(self.error)中
InfluxDBClientError: retention policy not found: autogen如何获得查询结果?
我检查了保留策略,其中还发现了错误:
client.query('SHOW RETENTION POLICIES')回溯(最近一次调用):
文件"",第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:{“错误”:“错误解析查询:找到EOF,预期在第1行,char 25"}
发布于 2018-07-03 13:51:45
将autogen更改为default
client.query('SELECT "duration" FROM "pyexample"."default"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')发布于 2022-05-02 23:26:06
这取决于您收到的错误消息。在我的例子中,我得到了错误“保持策略未找到:永远”,这意味着-一个名为“永远”的保留策略是找不到的。
我用以下方法修正了它:
influxuse collectdcreate retention policy "forever" on "collectd" duration 2d replication 1官方文件可以找到:管理留用政策
https://stackoverflow.com/questions/51152910
复制相似问题