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
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...