【问题标题】:How to get splunk report for different time ranges如何获取不同时间范围的 splunk 报告
【发布时间】:2020-08-19 13:02:31
【问题描述】:

我正在运行一个日期范围的 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

【问题讨论】:

    标签: splunk splunk-query


    【解决方案1】:

    一种方法是使用追加。

    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。

    【讨论】:

      【解决方案2】:

      上一个查询的一个问题是 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 命令。

      【讨论】:

      • 谢谢。我正在以每行显示不同时间范围详细信息的方式查找结果。我有点想通这个查询,但它没有返回百分比详细信息,我不确定它的效率如何。更新了我的问题。您能否提供一种实现百分比详细信息的方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多