我正在使用以下代码行在influxDB中添加指标数据。
def add_job_influx_db_metrics(tags_dict={}, values_dict={}, measurement='test'):
influxdb_client = InfluxDB.get_connection()
db_name = "mydb"
influxdb_client.switch_database(database=db_name)
current_time = time.strftime('%Y-%m-%dT%H:%M:%SZ',time.localtime(time.time()))
json_body = [
{
"measurement": measurement,
"tags": tags_dict,
"time": current_time,
"fields": values_dict
}
]
response = influxdb_client.write_points(points=json_body)
print "write_operation response", response
当我将其与Grafana集成时,不会显示数据,但是当我在127.0.0.1:8083上对其进行检查时,它显示的时间是1970-01-01T00:00:00Z。可能是以开始时间作为默认。我想采用“ 2015-8-19T07:15:00Z”形式的时间。如何在influxdb(python client)中获取时间字段,并且timePrecision是什么?
from datetime import datetime
current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
并在json_body-中使用这样的“时间”
"time": current_time
有用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句