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
SplunkTrust
SplunkTrust

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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...