InfluxDBClientError:找不到保留策略:autogen

时间:2018-07-03 10:59:26

标签: influxdb-python

我正在浏览https://www.influxdata.com/blog/getting-started-python-influxdb/文档,以使用python查询influxdb。

我能够创建数据库:

CEO

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

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

将json主体调用为:

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
    }
}
]

但是现在,我想使用以下方法从数据库中查询指标:

client.write_points(json_body)
True 

此查询导致错误:

  

文件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('results',[])

中      

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

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

如何获取查询结果?

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

InfluxDBClientError: retention policy not found: autogen

回溯(最近通话最近一次):

  

文件“”,第1行,在       client.query('SHOW RETENTION POLICIES')

     

查询中的文件“ /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行,字符25开”}

1 个答案:

答案 0 :(得分:1)

autogen更改为default

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