将两个不同的来源与流量/磁通中的不同时间戳组合

发布于 2025-02-03 19:02:54 字数 1598 浏览 4 评论 0原文

我有2个测量值如下:

metrics,app=app1 cpu=10 1654150510
metrics,app=app1 cpu=12 1654150512
metrics,app=app1 cpu=13 1654150514
metrics,app=app1 cpu=14 1654150516
metrics,app=app1 cpu=15 1654150519

“指标”测量的频率约为2/3秒。 第二个是:

http_requests,app=app1 response_time=12 1654150509
http_requests,app=app1 response_time=11 1654150510
http_requests,app=app1 response_time=15 1654150511
http_requests,app=app1 response_time=14 1654150512
http_requests,app=app1 response_time=13 1654150513
http_requests,app=app1 response_time=10 1654150514
http_requests,app=app1 response_time=12 1654150515
http_requests,app=app1 response_time=11 1654150516
http_requests,app=app1 response_time=13 1654150517
http_requests,app=app1 response_time=12 1654150518

http_requests的频率约为1秒。

我想将2个指标组合到一个表中。

_time,value_cpu,value_response_time
1654150509,10,12
1654150510,10,11
1654150511,12,15

由于时间戳可能有所不同,是否有办法将它们结合在磁通状态?是填充。我不确定时移是否会在这里有所帮助。尽管我不完全理解它。我认为需要某种倒数采样(不确定如何在通量中做到这一点)。有没有办法基于最接近时间的时间来数量测量? IE... 如果响应测量在时间实例上进行

1654150510,app=app1 response_time=10
1654150513,app=app1 response_time=12
1654150514,app=app1 response_time=11
1654150516,app=app1 response_time=13

,并且CPU在

1654150512,app=app1 cpu=20
1654150515,app=app1 cpu=30

当时出现的表是

_time,response_time,cpu
1654150510,10,
1654150513,12,20
1654150514,11,
1654150516,13,30

CPU值与最接近的时间戳(+/-差异)结合了点(+/-差异) 如何在InfluxDB中在flux中实现这一目标?

I have 2 measurements as follows:

metrics,app=app1 cpu=10 1654150510
metrics,app=app1 cpu=12 1654150512
metrics,app=app1 cpu=13 1654150514
metrics,app=app1 cpu=14 1654150516
metrics,app=app1 cpu=15 1654150519

The frequency of the "metrics" measurement is about once in 2/3 seconds.
And the second one is:

http_requests,app=app1 response_time=12 1654150509
http_requests,app=app1 response_time=11 1654150510
http_requests,app=app1 response_time=15 1654150511
http_requests,app=app1 response_time=14 1654150512
http_requests,app=app1 response_time=13 1654150513
http_requests,app=app1 response_time=10 1654150514
http_requests,app=app1 response_time=12 1654150515
http_requests,app=app1 response_time=11 1654150516
http_requests,app=app1 response_time=13 1654150517
http_requests,app=app1 response_time=12 1654150518

The frequency for http_requests is about 1 second.

I want to combine the 2 metrics into a single table.

_time,value_cpu,value_response_time
1654150509,10,12
1654150510,10,11
1654150511,12,15

As timestamps may be different, is there a way to combine them in flux? Is fill the way. I'm not sure if timeshift will help here. Although I didnt understand it completly. I assume some sort of downsampling is needed (not sure how to do that either in flux). Is there a way to mathch the measuerment based on the closest time differece?
IE...
if response measurements came at time instances

1654150510,app=app1 response_time=10
1654150513,app=app1 response_time=12
1654150514,app=app1 response_time=11
1654150516,app=app1 response_time=13

and CPU came in at

1654150512,app=app1 cpu=20
1654150515,app=app1 cpu=30

Then resulting table is

_time,response_time,cpu
1654150510,10,
1654150513,12,20
1654150514,11,
1654150516,13,30

The CPU value combines to the point with the closest timestamp (+/- difference)
How can this be achieved in flux in influxdb?

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

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

发布评论

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

评论(1

爱已欠费 2025-02-10 19:02:55

我想用gentregateWindow填充可以使用降采样。

替代方法是使用先前的值旋转并填充缺失值。至少从性能的角度来看,优势是,当在给定时间都没有测量中没有记录时,就没有创建任何新的行。

结果

from(bucket: "stackx")
 |> range(start: -1d)
 |> filter(fn: (r) => r._measurement == "metrics" or r._measurement == "http_requests")
 |> drop(columns: ["_measurement"]) // or remove from group other way
 |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
 |> sort(columns: ["_time"], desc: false)
 |> fill(column: "cpu", usePrevious: true)
 |> fill(column: "response_time", usePrevious: true)

_time,app,cpu,response_time
2022-06-02T06:15:09Z,app1,,12
2022-06-02T06:15:10Z,app1,10,11
2022-06-02T06:15:11Z,app1,10,15
2022-06-02T06:15:12Z,app1,12,14
2022-06-02T06:15:13Z,app1,12,13
2022-06-02T06:15:14Z,app1,13,10
2022-06-02T06:15:15Z,app1,13,12
2022-06-02T06:15:16Z,app1,14,11
2022-06-02T06:15:17Z,app1,14,13
2022-06-02T06:15:18Z,app1,14,12
2022-06-02T06:15:19Z,app1,15,12

I guess downsampling with aggregateWindow and fill could work.

Alternative way is to pivot and then fill missing values using previous value. The advantage, at least from performance point of view, is that when there is no record in neither measurement at given time, no new row filled with previous values is created.

With

from(bucket: "stackx")
 |> range(start: -1d)
 |> filter(fn: (r) => r._measurement == "metrics" or r._measurement == "http_requests")
 |> drop(columns: ["_measurement"]) // or remove from group other way
 |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
 |> sort(columns: ["_time"], desc: false)
 |> fill(column: "cpu", usePrevious: true)
 |> fill(column: "response_time", usePrevious: true)

the result would be

_time,app,cpu,response_time
2022-06-02T06:15:09Z,app1,,12
2022-06-02T06:15:10Z,app1,10,11
2022-06-02T06:15:11Z,app1,10,15
2022-06-02T06:15:12Z,app1,12,14
2022-06-02T06:15:13Z,app1,12,13
2022-06-02T06:15:14Z,app1,13,10
2022-06-02T06:15:15Z,app1,13,12
2022-06-02T06:15:16Z,app1,14,11
2022-06-02T06:15:17Z,app1,14,13
2022-06-02T06:15:18Z,app1,14,12
2022-06-02T06:15:19Z,app1,15,12
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文