【问题标题】:Data fields missing in the splunk outputsplunk 输出中缺少数据字段
【发布时间】:2017-02-14 18:01:24
【问题描述】:

我的 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 小时,它应该从影响时间开始以小时为基础进行汇总

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”显示一个空的“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、07: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

提前致谢。

【问题讨论】:

    标签: aggregation timespan splunk bucket


    【解决方案1】:

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

    我通过在我的数据上运行类似的东西来重现你的场景:

    [...]
    | 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 值覆盖到您自己的自定义字段中:

    [...]
    eval _time=time
    

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

    希望有帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 2013-06-07
    相关资源
    最近更新 更多