如何计算Splunk中的结果并将它们放在表中?

时间:2015-06-30 18:16:29

标签: splunk

我正在尝试在Splunk中创建一个表,其中包含几个已提取的字段以及当我向Splunk提供要搜索的字符串时返回的总数条目数。我遇到的问题是,当我使用stats命令获取返回的结果计数并将其传递给表时,它只是将所有字段留空,但显示返回结果计数的值。如果没有计数逻辑,表格会显示我所追求的所有值。以下是我的示例查询:

index=test "Failed to find file"
| table host, sourceUser, sourceApp, source
| rename host as "Server", sourceUser as "User", sourceApp as "Application", source as "Log"

以下是示例结果(由于我无法发布图片,所以在两行CSV中):

服务器,用户,应用程序,登录

MYSERVER1,JOESMITH,RadomApp,C:\用户\乔\ log.txt的

这将返回我要求的所有字段。如果我添加stats命令(如下所示),它将返回一个包含所有列的表,但唯一一个包含数据的是“错误计数”列:

index=test "Failed to find file"
| stats count as error
| table host, sourceUser, sourceApp, source, error
| rename host as "Server", sourceUser as "User", sourceApp as "Application", source as "Log", error as "Error Count"

示例结果:

服务器,用户,应用程序日志,的ErrorCount

1 ,,,,

了解最佳解决方法是什么?

1 个答案:

答案 0 :(得分:0)

我认识的人提出了解决方案,我需要更改'统计数据' line,以便最终查询如下所示:

index=test "Failed to find file"
| stats count as error by host, sourceUser, sourceApp, source
| table host, sourceUser, sourceApp, source, error
| rename host as "Server", sourceUser as "User", sourceApp as "Application", source as "Log", error as "Error Count"