使用 influxdb 记录高频时间序列数据

发布于 2025-01-15 01:45:08 字数 733 浏览 3 评论 0原文

我想每 10 毫秒记录一次数据。下面是示例代码:

with InfluxDBClient(url=url, token=token, org=org, enable_gzip=True) as client:
    with client.write_api(
        write_options=WriteOptions(
            batch_size=100, flush_interval=500, jitter_interval=0
        )
    ) as write_client:

        while True:
            time.sleep(0.01)
            val = np.random.randint(10)
            print(val)
            write_client.write(
                bucket,
                org,
                {
                    "measurement": "my_measurement",
                    "fields": {"my_value": int(val)},
                },
            )
            write_client.flush()

但是,上面的记录并没有按要求的频率进行记录。另外,在这种情况下如何处理批处理也让我感到困惑。

I want to record data every 10 milliseconds. Here is the sample code:

with InfluxDBClient(url=url, token=token, org=org, enable_gzip=True) as client:
    with client.write_api(
        write_options=WriteOptions(
            batch_size=100, flush_interval=500, jitter_interval=0
        )
    ) as write_client:

        while True:
            time.sleep(0.01)
            val = np.random.randint(10)
            print(val)
            write_client.write(
                bucket,
                org,
                {
                    "measurement": "my_measurement",
                    "fields": {"my_value": int(val)},
                },
            )
            write_client.flush()

However, the above does not record with a required frequency. Also, it is confusing for me how the batching will be handled in this case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北渚 2025-01-22 01:45:08

您需要为数据点指定时间,否则服务器接收到数据点时将为其分配服务器时间。批处理不会对其产生更大的影响。

You need to specify time for the data point, otherwise it will be assigned server time when it is received by the server. Batching won't affect it even more then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文