如何构建 splunk 查询以生成字段为 null 或非 null 的事件计数?
How to structure a splunk query to generate a count of events where the field is either null or not null?
我正在处理一些可能有也可能没有 user_name 字段的访问日志。我不需要做任何花哨的事情,我只想生成一个查询,该查询 returns 一个统计数据 table 包含事件计数,其中此字段为 null 或不为 null。例如,我的日志结构如下:
<timestamp><field1><field2><user_name><field4>
对于匿名连接,user_name 未记录,因此这些值为空。我可以很容易地获得所有非空值:
<base_query> user_name="*" | stats count
这给了我一个不错的 table 非空 user_name 字段:
count
------
812093
我还可以通过更多的工作来计算空字段的数量,但这看起来很混乱:
<base_query> | fillnull user_name value=NULL| search user_name=NULL | stats count
然后我得到一个空 user_name 字段的条目数。
count
-----
31215
但是,我真正想要的是将这两个组合成一个统计信息的单个查询 table,理想情况下:
not_null | null
----------------
812093 | 31215
谢谢!
有一个函数 "isNull(field)" ,你可以用它来计算然后计数
index=indxname search_condition
| eval countByFieldExists=if(isnull(field),"notExist","Exists")
| stats count by countByFieldExists
像这样的东西应该适合你
我正在处理一些可能有也可能没有 user_name 字段的访问日志。我不需要做任何花哨的事情,我只想生成一个查询,该查询 returns 一个统计数据 table 包含事件计数,其中此字段为 null 或不为 null。例如,我的日志结构如下:
<timestamp><field1><field2><user_name><field4>
对于匿名连接,user_name 未记录,因此这些值为空。我可以很容易地获得所有非空值:
<base_query> user_name="*" | stats count
这给了我一个不错的 table 非空 user_name 字段:
count
------
812093
我还可以通过更多的工作来计算空字段的数量,但这看起来很混乱:
<base_query> | fillnull user_name value=NULL| search user_name=NULL | stats count
然后我得到一个空 user_name 字段的条目数。
count
-----
31215
但是,我真正想要的是将这两个组合成一个统计信息的单个查询 table,理想情况下:
not_null | null
----------------
812093 | 31215
谢谢!
有一个函数 "isNull(field)" ,你可以用它来计算然后计数
index=indxname search_condition
| eval countByFieldExists=if(isnull(field),"notExist","Exists")
| stats count by countByFieldExists
像这样的东西应该适合你