InfluxDB 数据库基本操作

【influxdb 用户管理】
https://docs.influxdata.com/influxdb/v1.7/administration/authentication_and_authorization/#user-management-commands

【influxdb API方法】
https://docs.influxdata.com/influxdb/v1.7/tools/api/

InfluxDB HTTP endpoints:

Endpoint

Description

/debug/pprof

Use /debug/pprof to generate profiles for troubleshooting.

/debug/requests

Use /debug/requests/ to track HTTP client requests to the /write and /queryendpoints.

/debug/vars

Use /debug/vars to collect statistics

/ping

Use /ping to check the status of your InfluxDB instance and your version of InfluxDB.

/query

Use /query to query data and manage databases, retention policies, and users.

/write

Use /write to write data to a pre-existing database.

基础操作,语法支持: SELECT, DELETE, SHOW, CREATE, DROP, EXPLAIN, GRANT, REVOKE, ALTER, SET, KILL

# 连接实例,创建用户
# influx
create user admin with password 'influxdb' with all privileges
create database telegraf
create user telegraf with password 'telegraf'
grant all privileges on telegraf to telegraf
show databases
show users

# 安全访问
influx  -host '10.10.10.8' -port '8086' -username 'admin' -password 'influxdb'

show databases
use telegraf
show measurements 

# 查询
select time,usage_idle from autogen.cpu where time >= now() - 10m and host = 'kk' limit 10 offset 1
select mean("usage_idle") as "mui" from autogen.cpu where time >= now() - 1h and "cpu"='cpu-total' group by time(5m)

# 添加(新增 measurement: newtab)
insert newtab,host=kk,region=us_west value=0.77
insert newtab,host=mm,region=us_west value=0.88 1512345678912345678
select * from newtab

# 删除
delete from newtab where host='mm'
select * from newtab


# 【 GET 】SELECT 、 SHOW
curl -u admin:influxdb -G 'http://10.10.10.8:8086/query?db=telegraf' --data-urlencode 'q=SELECT * FROM newtab'
curl -u admin:influxdb -G 'http://10.10.10.8:8086/query?pretty=true&db=telegraf' --data-urlencode 'q=SELECT * FROM newtab'
curl -G 'http://10.10.10.8:8086/query?pretty=true&u=admin&p=influxdb&db=telegraf' --data-urlencode 'q=SELECT * FROM newtab'
curl --GET 'http://10.10.10.8:8086/query?pretty=true&u=admin&p=influxdb&db=telegraf' --data-urlencode 'q=SELECT * FROM newtab'
curl --GET 'http://10.10.10.8:8086/query?pretty=true&u=admin&p=influxdb' --data-urlencode "db=telegraf" --data-urlencode 'q=SELECT * FROM newtab'


# 【 POST 】ALTER 、CREATE 、DELETE 、DROP 、GRANT 、KILL 、REVOKE
curl -u admin:influxdb -XPOST 'http://10.10.10.8:8086/query?db=telegraf' --data-urlencode 'q=SELECT * INTO newtab2 FROM newtab'
curl -u admin:influxdb -XPOST 'http://10.10.10.8:8086/query?db=telegraf' --data-urlencode 'q=DROP MEASUREMENT newtab2'
curl -u admin:influxdb -XPOST 'http://10.10.10.8:8086/write?db=telegraf' --data-binary 'newtab,host=kk,region=us-west value=0.66 1434055562000000000'

猜你喜欢

转载自blog.csdn.net/kk185800961/article/details/84375614
今日推荐