Dashboards & Visualizations

In my dashboard, I want to convert the time range chosen into seconds and display the value in a panel

moizmmz
Path Finder

Say I select a time range from 11:00:00 to 12:00:00 (1 hour), I want my panel to show the value in seconds of the duration of the time range. i.e., panel should show 3600 seconds. Please help!

Tags (1)
0 Karma

vishaltaneja070
Motivator

Hello @moizmmz

Try this:

<form>
  <label>test1</label>
  <fieldset submitButton="false">
    <input type="time" token="time_tok" searchWhenChanged="true">
      <label>Select Time</label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>$time1$</title>
      <single>
        <search>
          <done>
            <set token="time1">$result.time_in_sec$</set>
          </done>
          <query>| makeresults | eval latest1=if($time_tok.latest|s$ == "now", now(),$time_tok.latest|s$)  | eval earliest1 = if($time_tok.latest|s$ == "now", relative_time(now(), $time_tok.earliest|s$), $time_tok.earliest|s$)  | eval time_in_sec= latest1 - earliest1 | eval time_in_sec = time_in_sec -  (time_in_sec % 60) | fields + time_in_sec</query>
          <earliest>$time_tok.earliest$</earliest>
          <latest>$time_tok.latest$</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </single>
    </panel>
  </row>
</form>
0 Karma

vnravikumar
Champion

Hi

Try this, seconds duration available in the token duration_sec. Modify accordingly

<form>
  <label>duration</label>
  <fieldset submitButton="false">
    <input type="time" token="timepicker">
      <label></label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
      <change>
        <eval token="time.earliest_epoch">if(isnum('earliest'),'earliest',relative_time(now(),'earliest')</eval>
        <eval token="time.latest_epoch">if(isnum('latest'),'latest',relative_time(now(),'latest')</eval>
        <eval token="duration_sec">($time.latest_epoch$-$time.earliest_epoch$)</eval>
      </change>
    </input>
</fieldset>
<row>
  <panel>
    <title>Time duration in seconds:$duration_sec$</title>
    <single>
      <search>
        <query>
          |makeresults | eval duration=$duration_sec$
        </query>
      </search>
    </single>
  </panel>
</row>
</form>

somesoni2
Revered Legend

YOu want to show the current time range (value in total number of seconds) in a single value panel OR within existing panel (in title OR in the table itself)?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...