<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to check if date is current date and calculate elapsed seconds since midnight in an eval? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/592223#M48574</link>
    <description>&lt;P&gt;It's telling me there's an error in the eval command.&amp;nbsp; I'll post the solution I ended up going with.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 14:25:07 GMT</pubDate>
    <dc:creator>bsg273</dc:creator>
    <dc:date>2022-04-04T14:25:07Z</dc:date>
    <item>
      <title>How to check if date is current date and calculate elapsed seconds since midnight in an eval?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/591552#M48520</link>
      <description>&lt;P&gt;I have a query that calculates the daily availability percentages of a given service for a set of hosts and is used to create a&amp;nbsp;&lt;SPAN&gt;multi-series line chart in a Splunk dashboard.&amp;nbsp; My ps.sh is running every 1800 seconds (30 minutes) on my Splunk forwarders, so I assume that it has run a total of 48 times on any given day to calculate the availability in an eval.&amp;nbsp; The problem is that on the current date, the ps.sh hasn't run all 48 times yet, so I can't get a valid calculation for the current date.&amp;nbsp; However, if I was able to check if the date in question was the current date, then calculate the number of seconds that have elapsed since the nearest midnight, I could divide that figure by 1800 to figure out the total number of times ps.sh would've run so far that day (hopefully I'm not overcomplicating this).&amp;nbsp; To illustrate, here's my query with the pseudo-code of desired logic in it using rhnsd as an example process:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=os host="my-db-*" sourcetype=ps rhnsd 
| timechart span=1d count by host 
| untable _time host count
| addinfo
| eval availability=if(&amp;lt;date is current date&amp;gt;,count/floor((info_max_time-&amp;lt;nearest midnight time&amp;gt;)/1800)*100,if(count&amp;gt;=48,100,count/48*100)) 
| rename _time as Date host as Host availability as Availability 
| fieldformat Date = strftime(Date, "%m/%d/%Y") 
| xyseries Date Host Availability&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help I could get with completing the above eval would be greatly appreciated, or if I'm overcomplicating this, any alternative methodologies would be more than welcome.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 17:39:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/591552#M48520</guid>
      <dc:creator>bsg273</dc:creator>
      <dc:date>2022-03-30T17:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if date is current date and calculate elapsed seconds since midnight in an eval?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/591820#M48555</link>
      <description>&lt;P&gt;To find the lapsed time since midnight, substract midnight ("@d") from the event time (_time).&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval secsSinceMidnight = _time - relative_time(_time, "@d")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 16:58:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/591820#M48555</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-03-31T16:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if date is current date and calculate elapsed seconds since midnight in an eval?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/591865#M48557</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=os host="my-db-*" sourcetype=ps rhnsd 
| timechart span=1d count by host 
| untable _time host count
| addinfo
| eval availability=if(strftime(_time,"%F")=strftime(now(),"%F"),count/floor(now()-relative_time(now(),"@d"))/1800)*100,if(count&amp;gt;=48,100,count/48*100)) 
| rename _time as Date host as Host availability as Availability 
| fieldformat Date = strftime(Date, "%m/%d/%Y") 
| xyseries Date Host Availability&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 19:16:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/591865#M48557</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2022-03-31T19:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if date is current date and calculate elapsed seconds since midnight in an eval?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/592223#M48574</link>
      <description>&lt;P&gt;It's telling me there's an error in the eval command.&amp;nbsp; I'll post the solution I ended up going with.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 14:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/592223#M48574</guid>
      <dc:creator>bsg273</dc:creator>
      <dc:date>2022-04-04T14:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if date is current date and calculate elapsed seconds since midnight in an eval?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/592225#M48575</link>
      <description>&lt;P&gt;This is the solution I ended up going with.&amp;nbsp; It simplifies my original logic a bit and also makes the graphs a bit easier to read by displaying hostname only instead of the fqdn.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=os host="my-db-*" sourcetype=ps rhnsd
| timechart span=1d count by host
| untable _time host count
| addinfo
| eval psRunCount=if(strftime(_time,"%m/%d/%Y")=strftime(info_max_time,"%m/%d/%Y"),floor((info_max_time-relative_time(info_max_time,"@d"))/1800),floor(86400/1800)), availability=if(count&amp;amp;gt;=psRunCount,100,round(count/psRunCount*100,2)), host=mvindex(split(host,"."),0)
| rename _time as Date host as Host availability as Availability
| fieldformat Date=strftime(Date,"%m/%d")
| xyseries Date Host Availability&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 14:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-check-if-date-is-current-date-and-calculate-elapsed/m-p/592225#M48575</guid>
      <dc:creator>bsg273</dc:creator>
      <dc:date>2022-04-04T14:31:16Z</dc:date>
    </item>
  </channel>
</rss>

