Splunk:如何通过id计算时间戳的差异?

问题描述 投票:0回答:2

我有这样的事件:

要求:

 Request "id":"123-abc-456"

回应:

 Response "id":"123-abc-456"

通过以下查询

(index=something "Response") OR (index=something "Request") 
|rex field=_raw "id\":\"(?<id>[a-z0-9-]+)" 
| table _time id

我得到一张表,其中包含一个事件的

id
_time
字段。看起来像这样:

_time id
2022-01-01 12:00:00:00 123-abc-456
2022-01-01 12:11:11:11 123-abc-456

现在,我想知道是否可以生成一个新表,其中

_time
字段按
id
字段分组?或者我是否必须更改查询才能获得这样的表,然后计算差异?但我不知道如何获得如下这样的表格...

Requesttime id Reponsetime
2022-01-01 12:00:00:00 123-abc-456 2022-01-01 12:11:11:11

非常感谢回复!

group-by merge splunk
2个回答
1
投票

Splunk 只能计算纪元(整数)形式的时间戳之间的差异。幸运的是,

_time
已经是纪元形式了(显示时自动转换为文本)。

如果请求时间和响应时间位于同一事件/结果中,则计算差异很简单

| eval diff=Responsetime - Requesttime

如果两个时间戳位于不同的事件/结果中,那么我们可以使用

range()
函数来获取它们的差异。

index=something "Request"
| rex field=_raw "id\":\"(?<id>[a-z0-9-]+)" 
| table _time id
| stats min(_time) as Requesttime, max(_time) as Responsetime, range(_time) as diff by id
```Format the timestamps manually```
| fieldformat Requesttime=strftime(Requesttime, "%Y-%m-%d %H:%M:S")
| fieldformat Responsetime=strftime(Responsetime, "%Y-%m-%d %H:%M:S")
| fieldformat diff=tostring(diff,"duration")

0
投票

在接受的答案中,strftime 中的

%
之前缺少
S

© www.soinside.com 2019 - 2024. All rights reserved.