Dashboards & Visualizations

How to use a token's earliest value in a query

bsg273
Path Finder

I have a dashboard with a timeframe dropdown created by a token called "query_time".  I'm trying to create a panel to show the availability of a given service/process over whatever period of time is selected in the "query_time" dropdown (I have my ps.sh running every 1800 seconds btw, hence the 1800 shown).  I thought it would be as simple as subtracting the two, as shown below, but I'm getting an error whenever I incorporate the $query_time.earliest$ into the query.  It seems to play nice if I were to use just $query_time.latest$ though.  Is there any way to get this time difference in the query without it erroring out?  Thanks in advance!

 

 

 

    <panel>
      <chart>
        <title>rhnsd Availability</title>
        <search>
          <query>index=os host="mydb1" sourcetype=ps rhnsd  | stats count | eval availability=count/(($query_time.latest$-$query_time.earliest$)/1800)*100) | fields availability</query>
          <earliest>$query_time.earliest$</earliest>
          <latest>$query_time.latest$</latest>
        </search>
        <option name="charting.axisY.maximumNumber">100</option>
        <option name="charting.chart">fillerGauge</option>
        <option name="charting.chart.rangeValues">[0,90,100]</option>
        <option name="charting.chart.stackMode">stacked</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.gaugeColors">["0xdc4e41","0x53a051"]</option>
        <option name="refresh.display">progressbar</option>
      </chart>
    </panel>

 

 

 

 

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
    <panel>
      <chart>
        <title>rhnsd Availability</title>
        <search>
          <query>
index=os host="mydb1" sourcetype=ps rhnsd
| stats count
| addinfo
| eval availability=count/((info_max_time-info_min_time)/1800)*100) 
| fields availability
          </query>
          <earliest>$query_time.earliest$</earliest>
          <latest>$query_time.latest$</latest>
        </search>
        <option name="charting.axisY.maximumNumber">100</option>
        <option name="charting.chart">fillerGauge</option>
        <option name="charting.chart.rangeValues">[0,90,100]</option>
        <option name="charting.chart.stackMode">stacked</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.gaugeColors">["0xdc4e41","0x53a051"]</option>
        <option name="refresh.display">progressbar</option>
      </chart>
    </panel>

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
    <panel>
      <chart>
        <title>rhnsd Availability</title>
        <search>
          <query>
index=os host="mydb1" sourcetype=ps rhnsd
| stats count
| addinfo
| eval availability=count/((info_max_time-info_min_time)/1800)*100) 
| fields availability
          </query>
          <earliest>$query_time.earliest$</earliest>
          <latest>$query_time.latest$</latest>
        </search>
        <option name="charting.axisY.maximumNumber">100</option>
        <option name="charting.chart">fillerGauge</option>
        <option name="charting.chart.rangeValues">[0,90,100]</option>
        <option name="charting.chart.stackMode">stacked</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.gaugeColors">["0xdc4e41","0x53a051"]</option>
        <option name="refresh.display">progressbar</option>
      </chart>
    </panel>
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...