如何获得不同时间范围的Splunk报告

问题描述

我正在为日期范围运行一个splunk查询。一切正常。我想针对不同的日期范围运行相同的查询。假设1天,7天和一个月。 一天运行的示例查询:

 index="a" env="test" MachineIdentifier source="D:\\Inetpub\\Logs\\app*.log" earliest=-2d latest=-1d 
| top limit=50 MachineIdentifier
| sort MachineIdentifier asc

当前,我通过修改“最早”和“最新”值并将其导出以进行合并来针对不同的日期范围运行此查询。

我想准备一个查询,该查询在单个报告中提供1天,7天等数据。有可能吗?

编辑:

想出了这个查询,但是我无法获得类似上面查询的百分比详细信息。如何在结果中显示百分比详细信息。

index="a" env="test" MachineIdentifier source="D:\\Inetpub\\Logs\\app*.log"  earliest=-2d@d latest=-1d@d 
|fields MachineIdentifier | eval marker="1DayData" 
| append 
[search index="a" env="test" MachineIdentifier source="D:\\Inetpub\\Logs\\app*.log"  earliest=-3d@d latest=-1d@d 
|fields MachineIdentifier | eval marker="2DaysData"] 
| stats count(eval(marker="1DayData")) AS 1DayCount,count(eval(marker="2DaysData")) AS 2DaysCount by MachineIdentifier

解决方法

一种方法是使用添加。

index="a" env="test" MachineIdentifier source="D:\\Inetpub\\Logs\\app*.log" earliest=-2d latest=-1d 
| top limit=50 MachineIdentifier
| sort MachineIdentifier asc 
| eval duration="daily"
| append 
    [search index="a" env="test" MachineIdentifier source="D:\\Inetpub\\Logs\\app*.log" earliest=-7d latest=-1d 
    | top limit=50 MachineIdentifier
    | sort MachineIdentifier asc
    | eval duration="weekly"]
| append 
    [search index="a" env="test" MachineIdentifier source="D:\\Inetpub\\Logs\\app*.log" earliest=-30d latest=-1d 
    | top limit=50 MachineIdentifier
    | sort MachineIdentifier asc 
    | eval duration="monthly"]

但这不是最有效的方法。出于性能原因,您可能要研究tstats。

,

上一个查询的一个问题是Splunk提取了3次数据。现在,其中涉及一些缓存等...,但是处理了3次数据。

这是另一种尝试减少数据检索量的尝试。尝试两个示例,看看哪种方法最适合您。

index=_internal earliest=31d@d
| eval now=now()
| eval date_range=case(
  _time>relative_time(now,"-1d@d"),"daily",_time>relative_time(now,"-7d@d"),"weekly",1==1,"monthly"
  )
| appendpipe [ | where date_range="daily" AND isnull(res_duration) | top limit=50 MachineIdentifier | eval res_duration="daily" ]
| appendpipe [ | where date_range="weekly" AND isnull(res_duration) | top limit=50 MachineIdentifier | eval res_duration="weekly" ]
| appendpipe [ | where date_range="monthly" AND isnull(res_duration) | top limit=50 MachineIdentifier | eval res_duration="monthly" ]
| where isnotnull(res_duration)
| table component count res_duration

根据要处理的数据量,您可能仍需要查看tstats命令。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...