如何在 splunk 中集群和创建时间表

How to Cluster and create a timechart in splunk

我有一个包含 LogMsg 错误消息的字段,我正在使用 cluster.

根据相似性进行分组

我想要实现的是显示带有分组错误的时间序列

index="my_index_here" LogLevel=ERROR
  | cluster showcount=t t=0.2 field=Message | eval "Error Count" = cluster_count
  | head 10 | timechart count("Error Count") By LogMsg span=60m

想法是这样的

  1. 获取所有错误消息LogLevel=ERROR
  2. 根据消息字段对项目进行分组| cluster showcount=t t=0.2 field=Message | eval "Error Count" = cluster_count
  3. 获得前 10 个结果| head 10
  4. 绘制时间表timechart count("Error Count") By LogMsg span=60m。时间图表应该有一个从集群生成的不同错误消息随时间变化的图,类似于
Message 8.00 9:00 10.00 11:00
Unable to authenticate 90 40 30 60
Another Error 80 40 30 60
Yet another error 70 40 30 60
--- --- --- --- ---
The 10th most frequent error 50 40 30 60

我上面的方法无法返回空白图,

调试 SPL 的方法是每次执行一个管道并在添加下一个管道之前验证结果。

我相信您会发现的一件事是 head 命令会破坏时间表。可能所有前 10 个结果都在同一小时内,因此结果可能不太有用。

“空白图”的一个常见原因是 statstimechart 命令引用了不存在的字段或空字段。您应该在调试期间发现哪个字段为空。

FWIW,这里有一个 运行-anywhere 查询类似于你的查询,它会生成一个图。

index=_internal log_level=INFO 
| cluster showcount=t t=0.2 field=event_message 
| eval "Error Count" = cluster_count 
| head 10 
| timechart count("Error Count") By group span=60m