【问题标题】:How to structure a splunk query to generate a count of events where the field is either null or not null?如何构造一个 splunk 查询以生成字段为空或不为空的事件计数?
【发布时间】:2020-01-08 16:40:40
【问题描述】:

我正在处理一些可能有也可能没有用户名字段的访问日志。我不需要做任何花哨的事情,我只想生成一个查询,该查询返回一个统计表,其中包含该字段为空或不为空的事件计数。例如,我的日志结构如下:

<timestamp><field1><field2><user_name><field4>

对于匿名连接,不会记录 user_name,因此这些值为 null。我可以很容易地获得所有非空值:

&lt;base_query&gt; user_name="*" | stats count

这给了我一个很好的非空用户名字段表:

count
------
812093

我还可以通过更多的工作来获得空字段的计数,但这似乎很混乱:

<base_query> | fillnull user_name value=NULL| search user_name=NULL | stats count

然后我得到一个带有空用户名字段的条目计数。

count
-----
31215

但是,我真正想要的是一个将这两者组合到一个统计表中的单个查询,理想情况下:

not_null | null
----------------
812093   | 31215

谢谢!

【问题讨论】:

    标签: splunk splunk-query


    【解决方案1】:

    有一个函数 "isNull(field)" ,你可以用它来评估然后计数

    index=indxname search_condition
    | eval countByFieldExists=if(isnull(field),"notExist","Exists") 
    | stats count by countByFieldExists
    

    这样的东西应该适合你

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 1970-01-01
      • 2015-04-18
      • 2017-04-20
      • 2019-09-05
      • 2021-01-09
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多