python修改influxdb的数据_Python操作Influxdb数据库

本文介绍了如何在Linux环境下安装InfluxDB并进行基本操作,包括数据的插入、显示所有表、删除表、修改数据保留时间等。接着讲解了使用Python的influxdb库往InfluxDB中插入数据的步骤,并提供了相关资源链接。
摘要由CSDN通过智能技术生成

1、influxdb基本操作

[root@test ~]# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.2.4.x86_64.rpm

[root@test ~]# yum localinstall influxdb-1.2.4.x86_64.rpm

[root@test ~]# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.1.0.x86_64.rpm

[root@test ~]# yum localinstall influxdb-1.1.0.x86_64.rpm

[root@test ~]# influx -precision rfc3339      #更改influxdb的时间显示方式为utc显示方式

>precision rfc3339

insert disk_free,hostname=server01 value=4422i 1435362189575692182     #添加数据并自定义时间戳

注意:

插入一条带时间戳的数据时,时间必需在数据保留策略时间内,否则该条数据无法插入

InfluxDB的insert中,表名与数据之间用逗号(,)分隔,tag和field之间用 空格分隔,多个tag或者多个field之间用逗号(,)分隔

> show measurements           #显示所有表

name: measurements

name

----

DomainBps

> show series from [表名]       #series表示这个表里面的数据可以在图表上画成几条线

> drop measurement [表名]    #删除一张表

> show retention policies on aliyun     #查询aliyun数据库的默认策略

name      duration      shardGroupDuration      replicaN     default

----           ----------        ------------------                 --------        -------

autogen      0s               168h0m0s                       1              true

> alter retention POLICY "autogen" on "aliyun" duration 200h     #更改数据的保留时间

name        duration        shardGroupDuration   replicaN   default

-------         ----------         ---------------------------   ----------     -------

autogen  200h0m0s           168h0m0s                   1            true

> drop retention policy [策略名] on [数据库名]        #删除策略

> create retention policy [策略名] on [数据库名] duration 48h/2d replication 1 default      #创建策略

说明:

name字段为策略名

duration字段的0表示数据永远保留,不自动删除

shardGroupDuration字段的时间表示查询时间在168h内的查询效率高,查询大于这个时间的效率会降低

replicaN字段表示副本个数

2、python往influxbd插入数据

yum -y install epel-release     #Centos6.8安装epel源

yum -y install python-pip

[root@test ~]#pip install influxdb

[root@test ~]#pip install --upgrade influxdb

[root@test ~]#pip uninstall influxdb

root@debian:~#apt-get install python-influxdb

from influxdb importInfluxDBClient

json_body=[

{"measurement": "table_name", #表名

"tags": {"host": "server01", #host和region为字段名,server01和us-west分别为host和region的值"region": "us-west"},"time": "2009-11-10T23:00:00Z", #插入的时间必需在数据保留时间范围内,如策略保留时间为7天,则传的时间不能为7天前

"fields": {"value": 240.64345 #插入的值不能为0

}

},

{"measurement": "table_name","tags": {"host": "server01","region": "us-west"},"time": "2018-04-22T011:05:00Z","fields": {"value": 240}

}

]

client= InfluxDBClient('localhost', 8086, 'root', 'root', 'database')

client.write_points(json_body)

参考链接:

https://www.cnblogs.com/shhnwangjian/p/6897216.html?utm_source=itdadao&utm_medium=referral

https://www.cnblogs.com/mafeng/p/6848166.html

https://github.com/influxdata/influxdb-python

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2017

https://www.cnblogs.com/MikeZhang/p/InfluxDBPythonOpt20170312.html

https://www.cnblogs.com/saneri/p/7528283.html       #psutil模块获取监控数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值