splunk输出中缺少数据字段

时间:2016-10-06 05:49:17

标签: aggregation timespan splunk bucket

我的splunk数据中有两个字段,名为“impact_time”和“incident_name”。现在我想基于“impact_time”和我给出的跨度来聚合这些事件名称。例如, 如果我给出1d的跨度,它应该汇总每个日期下的事件。

2016-06-28 a,b,c,d
2016-06-29 g,r,w,d
2016-06-30 f,e,r,t

如果我将跨度设为1小时,则应根据impact_time

的小时进行汇总
2016-06-28 03:00:00 a,b,c,d
2016-06-29 04:00:00 g,r,w,d
2016-06-30 05:00:00 f,e,r,t

我通过以下查询得到这个: -

index=sn impact=1 OR impact=2 | eval time = round( strptime(impact_start,"%Y-%m-%d %H:%M:%S"), 0 )| where time >= ' + timeStart + ' AND time<=' + timeEnd + '| bucket time span=' + hm + ' | stats values(number) as incident_name by time

但有一个问题。当我将聚合时间保持为“小时”时,如果小时没有数据,则不会显示“impact_time”的任何内容。如同,数据表中完全没有相应的impact_time。如果“impact_time”中没有数据显示,是否有任何方法可以显示“impact_time”的空“incident_number”字段?例如: -

2016-06-28 03:00:00 a,b,c,d
2016-06-29 04:00:00 g,r,w,d
2016-06-30 05:00:00 f,e,r,t
2016-06-30 08:00:00 f,e,r,t

这里时间06:00:00,0:00:00都没有数据。因此,数据输出中缺少这些字段而不是显示: -

2016-06-28 03:00:00 a,b,c,d
2016-06-29 04:00:00 g,r,w,d
2016-06-30 05:00:00 f,e,r,t
2016-06-30 06:00:00 (null or empty)
2016-06-30 07:00:00 (null or empty)
2016-06-30 08:00:00 f,e,r,t

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以使用bucket time span=方法,而不是使用timechart方法:

我通过在我的数据上运行类似的东西来重现您的方案:

[...]
| bucket _time span=1h
| stats values(hostIdentifier) as hosts

这产生了:

-------------------------------------------
| _time            |    hosts             |
-------------------------------------------
| 2016-10-10 22:00 | host1, host2, host3  |
-------------------------------------------
| 2016-10-10 23:00 | hosta, hostb, hostc  |
-------------------------------------------
| 2016-10-11 00:00 | hostf, hoste, hostd  |
-------------------------------------------  <---This is the gap!
| 2016-10-11 02:00 | host4, host5, host6  |
-------------------------------------------

然后我将查询更改为使用:

[...]
| timechart span=1h values(hostIdentifier) as hosts
| fillnull "hosts" value="No Host Data"

这产生了:

-------------------------------------------
| _time            |    hosts             |
-------------------------------------------
| 2016-10-10 22:00 | host1, host2, host3  |
-------------------------------------------
| 2016-10-10 23:00 | hosta, hostb, hostc  |
-------------------------------------------
| 2016-10-11 00:00 | hostf, hoste, hostd  |
-------------------------------------------
| 2016-10-11 01:00 |   No Host Data       | <---This _was_ the gap!
-------------------------------------------
| 2016-10-11 02:00 | host4, host5, host6  |
-------------------------------------------

如果省略fillnull节,它将只是该单元格中的空白值。

我认为此解决方案适用于您的数据集。一件事是Splunk使用内置的_time字段进行时间表。您可能需要将_time值覆盖到您自己的自定义字段a la:

[...]
eval _time=time

或者只是在所有时间计算中使用_time变量而不是time

希望有所帮助!