InfluxDBClientError: retention policy not found: autogen

InfluxDBClientError: retention policy not found: autogen

我正在阅读 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"')

此查询导致错误:

File ipython-input-31-6e47204db16b, line 1, in module client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py", line 420, in query in data.get('results', [])

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/resultset.py", line 25, in init raise InfluxDBClientError(self.error)

InfluxDBClientError: retention policy not found: autogen

如何获取查询结果?

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

client.query('SHOW RETENTION POLICIES')

回溯(最近调用最后):

File "", line 1, in client.query('SHOW RETENTION POLICIES')

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py", line 409, in query expected_response_code=expected_response_code

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py", line 286, in request raise InfluxDBClientError(response.content, response.status_code)

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

autogen改为default:

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

这取决于您收到的错误消息。就我而言,我收到错误“未找到保留策略:永远”,它转换为 - 未找到名为“永远”的保留策略

我通过以下方式修复了它:

  • 进入InfluxDBdocker容器
  • 启动influx
  • use collectd 到 select 数据库
  • 创建名为“永远”的新保留策略: create retention policy "forever" on "collectd" duration 2d replication 1

可以找到官方文档:Manage retention policy