首页 文章

如何使用Influxdb-python将正确的时间戳发送到Influxdb

提问于
浏览
0

我有潮流数据库 test 测量:

name: mes1
time          Amount     Buy_order_id Price     
----          ------     ------------ -----     
1529832177822 0.02294    132868375    130117.83

我想在Grafana制作图表,但所有数据都是在1970年 . 我还有其他衡量标准:

name: cpu_load_short
time                Bool_value Float_value Int_value String_value host     region
----                ---------- ----------- --------- ------------ ----     ------
1257894000000000000 true       0.64        3         Text         server01 us-west

这次工作正常 . 我发现,测量 cpu_load_short 中的时间存储在ns中,但测量 mes1 中的数据以ms存储 .

我从websocket那里收到 mes1 的时间 . cpu_load_short 的时间是从python生成的:

datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')

所有数据都通过Influxdb-python发送到Influxdb . 我试图调整 mes1 的时间并在数字末尾添加六个零:

'1529832177822' -> '1529832177822000000'

但我收到了:

OverflowError: signed integer is greater than maximum

如何将数据发送到Influxdb并从中生成图表,以便数据格式正确且日期正确?也许我错过了一些东西,但我无法弄清楚为什么我不能在ns中将数据发送到我的数据库但我可以用datetime发送它 . 任何人都能解释一下,问题出在哪里?

1 回答

  • 1

    我遇到了同样的问题,并且能够解决它,让我试着指导你 .

    当您使用Influxdb-python客户端将您的积分写入InfluxDB时,您可以在 write_points 方法中指定时间精度 . (http://influxdb-python.readthedocs.io/en/latest/api-documentation.html#influxdb.DataFrameClient.write_points

    一个例子:

    from influxdb import InfluxDBClient
    client = InfluxDBClient(host=host, port=port, database=database)
    client.write_points(value, time_precision='ms')
    

    这会将你的 ms 转换为 ns . 希望这可以帮助 .

相关问题