> 连接数据库 普通连接数据库: ``` ./influx -ssl -username influxuser -password user@influxDB -host ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com -port 3242 ``` 以json展示: ``` ./influx -ssl -username influxuser -password user@influxDB -host ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com -port 3242 -format=json ``` json以美观的方式展示 ``` ./influx -ssl -username influxuser -password user@influxDB -host ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com -port 3242 -format=json -pretty ``` > 使用数据库 ``` use dingding_influx show measurements ``` > 新建measurement ``` 创建名称是cpu的measurement: INSERT cpu,host=serverA,region=us_west value=0.64 select host, region, value from cpu 创建名称是temperature的measurement: INSERT temperature,machine=unit42,type=assembly external=25,internal=37 select * from temperature ``` > 删除measurement 删除measurement需要管理员权限 ``` drop measurement cpu ``` > 通过Postman请求数据 请求 ``` POST https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/query?u=influxuser&p=user@influxDB Headers: Content-Type application/x-www-form-urlencoded Body: db=dingding_influx q=select host, region, value from cpu ``` 请求成功返回 ``` { "results": [ { "statement_id": 0, "series": [ { "name": "cpu", "columns": [ "time", "host", "region", "value" ], "values": [ [ "2019-07-26T08:58:21.438818256Z", "serverA", "us_west", 0.64 ] ] } ] } ] } ``` 如果请求没有的measurement返回 ``` { "results": [ { "statement_id": 0 } ] } ``` 如果用户名错误、密码错误、用户名和密码同时错误返回 ``` { "error": "authorization failed" } ``` 如果数据库错误 ``` { "error": "error authorizing query: influxuser not authorized to execute statement 'SELECT host, region, value FROM cpu', requires READ on dingding_influ" } ``` 如果请求meaasurement中没有的字段,比如`select hos, region, value from cpu`返回 ``` { "results": [ { "statement_id": 0, "series": [ { "name": "cpu", "columns": [ "time", "hos", "region", "value" ], "values": [ [ "2019-07-26T08:58:21.438818256Z", null, "us_west", 0.64 ] ] } ] } ] } ``` 如果q值为空返回 ``` { "error": "missing required parameter \"q\"" } ``` **时间戳格式** 默认数据的时间格式是UTC,编码是RFC3339, 例如`2015-08-04T19:05:14.318570484Z`, 如果想反悔Unix格式,使用`epoch`字段。 ``` epoch=h,m,s,ms,u,ns ``` **分块Chunking** 默认分块的数量是10000个数据据点,如果想改变分块大小,通过`chunked`和`chunk_size`设置。 ``` chunked=true chunk_size=20000 ``` > Postman写入数据 内部是以二进制方式写入数据。阿里云时序数据库API默认的写入时间是在5秒之内,如果一次性写入过多的数据,写入时间超过5秒,就不保证所有数据都被写入。所以当数据点比较多,比如有5000个数据点,需要把数据拆分。 单点写入数据点 ``` POST https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/write?db=dingding_influx&u=influxuser&p=user@influxDB Body: cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000 ``` 返回类型是204(No Content)。 多点写入数据点(没有成功) ``` POST https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/write?db=dingding_influx&u=influxuser&p=user@influxDB Body: cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257 cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257' ``` > 故障排除 使用浏览器打开。 ``` 总览页: https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof?u=influxuser&p=user@influxDB https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/goroutine?u=influxuser&p=user@influxDB https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/heap?u=influxuser&p=user@influxDB https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/mutex?u=influxuser&p=user@influxDB https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/threadcreate?u=influxuser&p=user@influxDB ``` > 跟踪请求 ``` 默认跟踪10秒内的请求: https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/requests?u=influxuser&p=user@influxDB 跟踪1分钟内的请求: https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/requests?seconds=60&u=influxuser&p=user@influxDB ``` > 运行时的统计信息 使用/ping检查TSDB For InfluxDB®实例的状态和TSDB For InfluxDB®的版本。使用Postman请求。 ``` GET https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/ping?u=influxuser&p=user@influxDB 返回204 在Headers里面有版本信息 ```