0

我在多台计算机上生成列出未运行的服务名称的事件。我想制作一个图表来显示最有问题的服务名称。

我可以使用以下内容获取仪表板的表格:

ComputerName="*.ourDomain.com" sourcetype="WinEventLog:Application" EventCode=7223 SourceName="internalSystem" 
| eval Date_Time=strftime(_time, "%Y-%m-%d %H:%M") 
| table host, Date_Time, Message, EventCode

典型消息将包含:

The following services were not running after 5603 seconds and a start command has been sent:
Service1
Service2
The following services were not running after 985 seconds and a start command has been sent:
Service2
Service3

使用正则表达式,我可以创建一个命名组,但第一行除外。(?<Services>((?<=\n)).*) 但是,我认为这不是正确的方法,因为我不知道如何使用这些信息对图表进行估值。

所以本质上,我如何从 Splunk 中的消息中获取和统计服务名称?

编辑1:几天后回到这个。我使用正则表达式创建了一个名为“服务”的字段提取,它在第一行之后抓取每条消息的内容。如果我使用| stats count BY Services它将每条消息作为一个整体而不是里面的行来计数。结果如下所示:

Service1 Service2 | Count: 1
Service2 Service3 | Count: 1

我的意图是让它将每一行视为自己的值,因此结果如下所示:

Service1 | Count: 1
Service2 | Count: 2
Service3 | Count: 1

我试过| mvexpand Services了,但它并没有改变输出,所以我认为我要么使用不当,要么在这里不适用。

4

3 回答 3

0

我最终使用 split() 和 mvexpand 来解决这个问题。这最终奏效了:

My search
| eval events=split(Service, "
")
| mvexpand events
| eval events=replace(events, "[\n\r]", "")
| stats count BY events

我必须添加 replace() 方法,因为仅列出一个服务的任何事件与具有多个服务的事件的处理方式不同,在对具有多个服务的事件进行拆分之后,每个服务都有一个回车符,因此是替换。

我的最终结果仪表板图表: 在此处输入图像描述

于 2022-02-14T21:43:35.577 回答
0

我认为你可以用stats命令来做到这一点。

| stats count by service

将为每项服务多次出场。然后,您可以选择条形图可视化来创建图表。

于 2022-02-10T14:39:11.510 回答
0

对于干净的图表下拉:

index="yourIndex" "<searchCriteria>"  | stats count(eval(searchmatch(" 
<searchCriteria>"))) as TotalCount 
count(eval(searchmatch("search1"))) as Name1 
count(eval(searchmatch("search2" ))) as Name2 
count(eval(searchmatch("search3"))) as Name3 
| transpose 5
| rename column as "Name", "row 1" as "Count"

带有百分比的水平表示例:

index=something "Barcode_Fail" OR "Barcode_Success" | stats 
count(eval(searchmatch("Barcode_Success"))) as SuccessCount 
count(eval(searchmatch("Barcode_Fail"))) as FailureCount             
count(eval(searchmatch("Barcode_*"))) as Totals | eval 
Failure_Rate=FailureCount/Totals |eval Success_Rate=SuccessCount/Totals
于 2022-02-24T00:39:38.500 回答