Splunk:从每个事件中提取多个值

Splunk : extract multiple values from each event

我是 Splunk 查询的新手,我不知道如何从同一事件中提取多个值。我正在处理看起来像这样的事件:

...
starting count: 12345678
ending count: 12347890
total time: ...
....

我想提取与“开始计数”和“结束计数”相关的值,并创建一个比较这两个值的图表。 到目前为止,我能够使用此查询提取一组值

rex field=_raw "starting count: (?<StartCount>\d+)"

但是我怎样才能提取两个不同的值并进行比较呢?提前致谢。

如果您要制作图表,是否意味着您有多个事件并且每个事件都包含开始计数和结束计数?

如果是这样,用 rex 提取开始计数和结束计数(就像您建议的那样),然后 eval 差值。像这样的东西:

| rex field=_raw "starting count: (?<StartCount>\d+)"
| rex field=_raw "ending count: (?<EndCount>\d+)"
| eval difference=EndCount-StartCount
| table _time StartCount EndCount difference

这是一个“运行 anywhere”版本,它可以生成自己的测试数据:

| makeresults count=2
| streamstats count
| eval _raw=if(count=1,"starting count: 12345678 ending count: 12346789 total time: ...","starting count: 12347890 ending count: 12349999 total time: ...")
| eval _time=if(count=1,_time-1,_time)

| rex field=_raw "starting count: (?<StartCount>\d+)"
| rex field=_raw "ending count: (?<EndCount>\d+)"
| eval difference=EndCount-StartCount
| table _time StartCount EndCount difference