Splunk Search

カスタム時間で指定した時間からさらに時間を指定する方法

appleman
Contributor

サーチをする際に、カスタム時間で時間を指定し(○月○日の断面等)、出た結果に対し、更にそれから1週間前のデータと比べるサーチ文をご教授下さい。

sourcetype=A | stats count by host | append [search earliest=-7d@w0 latest=@w0 sourcetype=A | stats count by host]

上記のサーチではappend前のサーチはカスタム時間を、append以下のサーチでは単純に指定した時間でサーチをしてしまっていて、カスタム時間を読み取ってくれませんでした。

Tags (3)
0 Karma
1 Solution

melonman
Motivator

通常のサーチ画面だと、うまくearliest/latestをサブサーチとメインサーチで共有できないので、Viewをつかうか、Macroを使うかして、任意の1日と、任意の日から1週間前や1日前などの過去の1日との比較を行うとなんとなく、それっぽいものができそうです。

例えば、以下の様なダッシュボードを、すこし編集すれば、いけそうですが、、、
どうでしょうか。

alt text

<?xml version='1.0' encoding='utf-8'?>
<form>
  <label>P1</label>
  <fieldset>
    <input type="text" token="date">
      <label>Specify the Date (YYYY/MM/DD)</label>
      <default>2013/08/10</default>
      </input>    
    <input type="dropdown" token="past">
        <label>Past</label>
        <choice value="-1d">-1 day</choice>
        <choice value="-1w">-1 week</choice>
        <choice value="-1mon">-1 month</choice>
        <choice value="-1year">-1 year</choice>
        <default>-1 week</default>
      </input>    
  </fieldset>
  <row>
    <table>
      <title>Selected Data</title>
        <searchString>

[| stats count | eval earliest=strptime("$date$","%Y/%m/%d") | eval latest=relative_time(earliest, "+1d") | return earliest latest ] | stats count by host | eval tag="$date$" | append [ search [ | stats count |  eval earliest=relative_time(strptime("$date$","%Y/%m/%d"),"$past$") | eval latest=relative_time(earliest, "+1d")  | return earliest latest ] | stats count by host | eval tag=strftime(relative_time(strptime("$date$","%Y/%m/%d"),"$past$"),"%Y/%m/%d") ] | xyseries host tag count

      </searchString>
    </table>
  </row>
</form>

View solution in original post

HiroshiSatoh
Champion

私もダッシュボードでやることに賛成ですが、serch文で無理やり編集してみました。
appendが逆になりますがデータはうまく抽出できていると思います。

sourcetype=A [| stats count |addinfo |eval earliest=relative_time(info_min_time,"-7d@d") | eval latest=relative_time(info_min_time, "-6d@d") | return earliest latest ]|stats count by host|append [search sourcetype=A |stats count by host]

appleman
Contributor

ご回答ありがとうございます。サーチで試してみます。

0 Karma

melonman
Motivator

通常のサーチ画面だと、うまくearliest/latestをサブサーチとメインサーチで共有できないので、Viewをつかうか、Macroを使うかして、任意の1日と、任意の日から1週間前や1日前などの過去の1日との比較を行うとなんとなく、それっぽいものができそうです。

例えば、以下の様なダッシュボードを、すこし編集すれば、いけそうですが、、、
どうでしょうか。

alt text

<?xml version='1.0' encoding='utf-8'?>
<form>
  <label>P1</label>
  <fieldset>
    <input type="text" token="date">
      <label>Specify the Date (YYYY/MM/DD)</label>
      <default>2013/08/10</default>
      </input>    
    <input type="dropdown" token="past">
        <label>Past</label>
        <choice value="-1d">-1 day</choice>
        <choice value="-1w">-1 week</choice>
        <choice value="-1mon">-1 month</choice>
        <choice value="-1year">-1 year</choice>
        <default>-1 week</default>
      </input>    
  </fieldset>
  <row>
    <table>
      <title>Selected Data</title>
        <searchString>

[| stats count | eval earliest=strptime("$date$","%Y/%m/%d") | eval latest=relative_time(earliest, "+1d") | return earliest latest ] | stats count by host | eval tag="$date$" | append [ search [ | stats count |  eval earliest=relative_time(strptime("$date$","%Y/%m/%d"),"$past$") | eval latest=relative_time(earliest, "+1d")  | return earliest latest ] | stats count by host | eval tag=strftime(relative_time(strptime("$date$","%Y/%m/%d"),"$past$"),"%Y/%m/%d") ] | xyseries host tag count

      </searchString>
    </table>
  </row>
</form>

appleman
Contributor

ご回答ありがとうございます。このやり方で、sourcetype等を指定する場合は、サーチのどこで指定すればよろしいのでしょうか。
[| stats...の前にsourcetype=Aと指定したのですが、ダッシュボード上では読み取らず、"The job appears to have expired or has been canceled. Splunk could not retrieve data for this search."というメッセージが表示されました。

0 Karma

linu1988
Champion

Could you try:

SourceType = A | stats count by host | append [search SourceType=A earliest = -1w@w latest =@w0 | stats count by host]

0 Karma

melonman
Motivator

指定した1日分と、1週間前の日の1日分のStats count by hostの結果をくらべるということですね?

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...