Splunk Search

How to put 2 different time fraims in dashboard

ivana27
Path Finder

Dears,

please can you help?

I have dashboard with several panels including graphs and reports. I would like create 2 paralel reports which will have different time frame in order to see values. In source i have main time frame 

<earliest>$searchtime.earliest$</earliest>
<latest>$searchtime.latest$</latest>

Which will be applied to one report and i would like to apply something like this on second paralel one

<earliest>$searchtime.earliest$ - 7d</earliest>
<latest>$searchtime.latest$ -7d</latest>

Is this possible?

Thank you

0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@ivana27 

Yes, you can do this either by having a second time picker, with a different token so that the user can select the comparative time range, or you can have a single time picker and then use a fixed relative time to that, which you can calculate if the user changes the original search time.

See this example dashboard. The first row shows the two time picker options and the second row shows how the right hand panel adjusts to a 7 day relative range to the left hand panel using a hidden search in the source.

<form>
  <label>Time Pickers</label>
  <init>
    <set token="earliest4">-8d@d</set>
    <set token="latest4">-7d@d</set>
  </init>
  <fieldset submitButton="false">
  </fieldset>
  <row>
    <panel>
      <input type="time" token="time_range_1">
        <label>First range</label>
        <default>
          <earliest>-1d@d</earliest>
          <latest>@d</latest>
        </default>
      </input>
    </panel>
    <panel>
      <input type="time" token="time_range_2">
        <label>Second range</label>
        <default>
          <earliest>-2d@d</earliest>
          <latest>-1d@d</latest>
        </default>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <chart>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$time_range_1.earliest$</earliest>
          <latest>$time_range_1.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
    <panel>
      <chart>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$time_range_2.earliest$</earliest>
          <latest>$time_range_2.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
  </row>
  <row>
    <panel>
      <input type="time" token="time_range_3">
        <label>Third range</label>
        <default>
          <earliest>-1d@d</earliest>
          <latest>@d</latest>
        </default>
      </input>
      <table depends="$show_hidden$">
        <title>This simple search - is hidden - but is used to calculate the relative time for the second table</title>
        <search>
          <query>| makeresults 
| addinfo
          </query>
          <earliest>$time_range_3.earliest$</earliest>
          <latest>$time_range_3.latest$</latest>
          <done>
            <eval token="earliest4">relative_time($result.info_min_time$, "-7d")</eval>
            <eval token="latest4">relative_time($result.info_max_time$, "-7d")</eval>
            <eval token="e3">strftime($result.info_min_time$, "%F %T")</eval>
            <eval token="l3">strftime($result.info_max_time$, "%F %T")</eval>
            <eval token="e4">strftime($earliest4$, "%F %T")</eval>
            <eval token="l4">strftime($latest4$, "%F %T")</eval>
          </done>
        </search>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <chart>
        <title>Time range 3 $e3$ to $l3$</title>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$time_range_3.earliest$</earliest>
          <latest>$time_range_3.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
    <panel>
      <chart>
        <title>Time range 4 - $e4$ to $l4$</title>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$earliest4$</earliest>
          <latest>$latest4$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
  </row>
</form>

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@ivana27 

Yes, you can do this either by having a second time picker, with a different token so that the user can select the comparative time range, or you can have a single time picker and then use a fixed relative time to that, which you can calculate if the user changes the original search time.

See this example dashboard. The first row shows the two time picker options and the second row shows how the right hand panel adjusts to a 7 day relative range to the left hand panel using a hidden search in the source.

<form>
  <label>Time Pickers</label>
  <init>
    <set token="earliest4">-8d@d</set>
    <set token="latest4">-7d@d</set>
  </init>
  <fieldset submitButton="false">
  </fieldset>
  <row>
    <panel>
      <input type="time" token="time_range_1">
        <label>First range</label>
        <default>
          <earliest>-1d@d</earliest>
          <latest>@d</latest>
        </default>
      </input>
    </panel>
    <panel>
      <input type="time" token="time_range_2">
        <label>Second range</label>
        <default>
          <earliest>-2d@d</earliest>
          <latest>-1d@d</latest>
        </default>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <chart>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$time_range_1.earliest$</earliest>
          <latest>$time_range_1.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
    <panel>
      <chart>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$time_range_2.earliest$</earliest>
          <latest>$time_range_2.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
  </row>
  <row>
    <panel>
      <input type="time" token="time_range_3">
        <label>Third range</label>
        <default>
          <earliest>-1d@d</earliest>
          <latest>@d</latest>
        </default>
      </input>
      <table depends="$show_hidden$">
        <title>This simple search - is hidden - but is used to calculate the relative time for the second table</title>
        <search>
          <query>| makeresults 
| addinfo
          </query>
          <earliest>$time_range_3.earliest$</earliest>
          <latest>$time_range_3.latest$</latest>
          <done>
            <eval token="earliest4">relative_time($result.info_min_time$, "-7d")</eval>
            <eval token="latest4">relative_time($result.info_max_time$, "-7d")</eval>
            <eval token="e3">strftime($result.info_min_time$, "%F %T")</eval>
            <eval token="l3">strftime($result.info_max_time$, "%F %T")</eval>
            <eval token="e4">strftime($earliest4$, "%F %T")</eval>
            <eval token="l4">strftime($latest4$, "%F %T")</eval>
          </done>
        </search>
      </table>
    </panel>
  </row>
  <row>
    <panel>
      <chart>
        <title>Time range 3 $e3$ to $l3$</title>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$time_range_3.earliest$</earliest>
          <latest>$time_range_3.latest$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
    <panel>
      <chart>
        <title>Time range 4 - $e4$ to $l4$</title>
        <search>
          <query>index=_audit | timechart span=1h count by user
          </query>
          <earliest>$earliest4$</earliest>
          <latest>$latest4$</latest>
        </search>
        <option name="charting.chart">line</option>
      </chart>
    </panel>
  </row>
</form>
Get Updates on the Splunk Community!

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...