1

我记录了 Splunk 中出现的语句,如下所示。

info Request method=POST, time=100, id=12345

info Response statuscode=200, time=300, id=12345

我正在尝试编写一个 Splunk 查询,该查询将从 info Request 和 info Response 开头的行中提取时间参数,并基本上找到时间差。有没有办法在查询中做到这一点?我能够从每个语句中分别提取值,但不能同时提取两个值。

我希望得到类似下面的东西,但我猜管道不起作用:

... | search log="info Request*" | rex field=log "time=(?<time1>[^\,]+)" | search log="info Response*" | rex field=log "time=(?<time2>[^\,]+)" | table time1, time2

非常感谢任何帮助。

4

1 回答 1

1

一般流程:

  1. 将类型提取到字段中
  2. 计算响应和请求时间
  3. 按 ID 分组
  4. 计算差异

您可能想要使用 stats(latest) 以外的其他内容,但如果每个 id 只有一个请求/响应,则无关紧要。

| rex field=_raw "info (?<type>\w+).*"
| eval requestTime = if(type="Request",time,NULL)
| eval responseTime = if(type="Response",time,NULL)
| stats latest(requestTime) as requestTime latest(responseTime) as responseTime by id
| eval diff = responseTime - requestTime
于 2018-02-27T23:56:30.453 回答