influxDB --- 1

RESTful 接口操作

插入及查询操作:

 
  1. # code from www.361way.com
  2. now=$(date '+%FT%T.000Z')
  3. tomorrow=$(date -v +1d '+%FT%T.000Z')
  4. echo "creating database"
  5. curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE foo"
  6. echo "creating retention policy"
  7. curl -G http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY bar ON foo DURATION INF REPLICATION 1 DEFAULT"
  8. echo "inserting data"
  9. curl -d "{\"database\" : \"foo\", \"retentionPolicy\" : \"bar\", \"points\": [{\"measurement\": \"cpu\", \"tags\": {\"region\":\"uswest\",\"host\": \"server01\"},\"time\": \"$now\",\"fields\": {\"value\": 100}}]}" -H "Content-Type: application/json" http://localhost:8086/write
  10. echo "inserting data"
  11. curl -d "{\"database\" : \"foo\", \"retentionPolicy\" : \"bar\", \"points\": [{\"measurement\": \"cpu\", \"tags\": {\"region\":\"uswest\",\"host\": \"server01\"},\"time\": \"$tomorrow\",\"fields\": {\"value\": 200}}]}" -H "Content-Type: application/json" http://localhost:8086/write
  12. sleep 1
  13. echo "querying data"
  14. curl -G http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT count(value) FROM \"foo\".\"bar\".cpu"
  15. echo "querying data"
  16. curl -G http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT count(value) FROM \"foo\".\"bar\".cpu where time < now() + 10d"

GZIP压缩数据插入及查询:

 
  1. # code from www.361way.com
  2. echo "inserting data"
  3. curl -v -i -H "Content-encoding: gzip" -H "Content-Type: application/json" -X POST -T foo.json.gz http://localhost:8086/write
  4. rm foo.json.gz
  5. echo "querying data with gzip encoding"
  6. curl -v -G --compressed http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT sum(value) FROM \"foo\".\"bar\".cpu GROUP BY time(1h)"

还可以指定数据保存策略及表的各关键值插入:

 
  1. echo "creating retention policy"
  2. curl -G http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY bar ON foo DURATION 300d REPLICATION 3 DEFAULT"
  3. curl -d '{"database" : "foo", "retentionPolicy" : "bar", "points": [{"measurement": "network", "tags": {"host": "server01","region":"uswest"},"time": "2015-02-26T22:01:11.703Z","fields": {"rx": 2342,"tx": 9804}}]}' -H "Content-Type: application/json" http://localhost:8086/write
  4. curl -d '{"database" : "foo", "retentionPolicy" : "bar", "points": [{"measurement": "network", "tags": {"host": "server01","region":"useast"},"time": "2015-02-27T22:01:11.703Z","fields": {"rx": 4324,"tx": 7930}}]}' -H "Content-Type: application/json" http://localhost:8086/write

更多可以参考github上的测试内容

无论是influx还是通过RESETful 参数进行查询,其还有pertty参数可以使输出的json格式更加美观 。除此之外,influx命令还有column、CSV等格式输出,influx命令支持通过import参数输入类csv类格式的数据。

五、influxdb.conf配置web管理

当前版本的influxdb,默认情况下未开启web管理功能。可以通过修改influxdb.conf文件中admin项的配置开启web管理界面,具体如下:

 
  1. [admin]
  2. # Determines whether the admin service is enabled.
  3. enabled = true
  4. # The default bind address used by the admin service.
  5. bind-address = ":8083"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值