Hi, I have a python script to monitor linux system. When I query a point using python script, the time is not localtime. Python script is as follows:
import influxdb
n = influxdb.InfluxDBClient('127.0.0.1', '8086','root','123456', 'test')
res = n.query("select cpu, mem, mmcblk0, mmcblk0_r, mmcblk0_w, rec, trans, net, tcp, retrans from \"127.0.0.1\" where time>'2020-11-14 21:30:07' and time<'2020-11-14 21:31:07' and type='system' tz('Asia/Shanghai')")
the result is:
'time': '2020-11-14T13:30:07.461109Z', 'cpu': 8.29
'time': '2020-11-14T13:30:10.603102Z', 'cpu': 2.26
'time': '2020-11-14T13:30:13.684848Z', 'cpu': 4.75
'time': '2020-11-14T13:30:16.828245Z', 'cpu': 1.25
'time': '2020-11-14T13:30:19.911986Z', 'cpu': 8.01
'time': '2020-11-14T13:30:23.053864Z', 'cpu': 1.0
'time': '2020-11-14T13:30:26.136214Z', 'cpu': 5.23
When I run the same query in InfluxDB shell, the time is localtime, as follows:
use test
precision rfc3339
select cpu, mem, mmcblk0, mmcblk0_r, mmcblk0_w, rec, trans, net, tcp, retrans from "127.0.0.1" where time>'2020-11-14 21:30:07' and time<'2020-11-14 21:31:07' and type='system' tz('Asia/Shanghai')
the result is:
time cpu
---- ---
2020-11-14T21:30:07.461108798+08:00 8.29
2020-11-14T21:30:10.603102483+08:00 2.26
2020-11-14T21:30:13.684848386+08:00 4.75
2020-11-14T21:30:16.828244687+08:00 1.25
2020-11-14T21:30:19.911986384+08:00 8.01
2020-11-14T21:30:23.053864202+08:00 1
2020-11-14T21:30:26.136213792+08:00 5.23
version:
python 3.8
influxdb 1.8.3
python-influxdb 5.3.0
Why the above two ways are different? Can you tell me how to modify python script? I don’t want to write a python script to convert time.
thank you for helping me !