<?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: Relative time and stats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63095#M15581</link>
    <description>&lt;P&gt;So the Target number of transactions is 15 - we want to see that as a steady constant in the graph, the rest should be active and inactive.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Dec 2012 22:16:32 GMT</pubDate>
    <dc:creator>asarolkar</dc:creator>
    <dc:date>2012-12-13T22:16:32Z</dc:date>
    <item>
      <title>Relative time and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63091#M15577</link>
      <description>&lt;P&gt;I have a somewhat complicated question about how the now() method applies in the context of stats.&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I have a splunk search to weed out accounts with no transactions in the last 24 hours&lt;BR /&gt;
I am using now() to determine a cutoff date for weeding out those accounts. &lt;BR /&gt;
&lt;STRONG&gt;lastTransactionProcessed is provided as a field by sourcetype="banklog" and is always populated&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="banklog" | eval cutOffTime=relative_time(now(),"-48h") | where lastTransactionProcessed&amp;gt;cutOffTime |  dedup accountNum | table accountNum
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above query works as expected which is great.&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;The problem is that I am expected to create a trend (using stats) for the last 4 days for this search and when I get now() involved with stats (see below), things dont work out as I hoped.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="banklog" | eval cutOffTime=relative_time(now(),"-48h") | where lastTransactionProcessed&amp;gt;cutOffTime | bucket span=1d _time | dedup accountNum _time | eval target=15 | eventstats dc(accountNum) as "successCount" | eval failures=target-successCount | stats first(target) as Target, c(successCount) as Success by _time | eval failures=15-Success
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am interested in simply plotting success versus failure here and I schedule the time interval for this search for -4d@d to now. &lt;/P&gt;

&lt;P&gt;I only get results for one day (which is the last 24 hours).&lt;/P&gt;

&lt;P&gt;Any clues so as to what I might be doing wrong here ?  &lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2012 19:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63091#M15577</guid>
      <dc:creator>asarolkar</dc:creator>
      <dc:date>2012-12-13T19:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Relative time and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63092#M15578</link>
      <description>&lt;P&gt;You are working with 4 different time fields, yes?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;now()&lt;/CODE&gt; is the time that this search started&lt;BR /&gt;&lt;BR /&gt;
&lt;CODE&gt;cutOffTime&lt;/CODE&gt; is 48 hours before this search started&lt;BR /&gt;&lt;BR /&gt;
&lt;CODE&gt;lastTransactionProcessed&lt;/CODE&gt; is found in the event&lt;BR /&gt;&lt;BR /&gt;
&lt;CODE&gt;_time&lt;/CODE&gt; is the timestamp of the event  &lt;/P&gt;

&lt;P&gt;Your &lt;CODE&gt;where&lt;/CODE&gt; command is cutting off a number of events.&lt;BR /&gt;
I might have done it like this instead&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=banklog
| eval accountStatus = if(lastTransactionProcessed &amp;gt; relative_time(_time,"-48h"),"Active","Inactive")
| bucket _time span=1d
| stats count by accountNum accountStatus _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My stats command is probably wrong, but I am having difficulty figuring out what &lt;CODE&gt;target&lt;/CODE&gt; means, as well as the definition of success or failure.  You could also&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=banklog
| eval accountStatus = if(lastTransactionProcessed &amp;gt; relative_time(_time,"-48h"),"Active","Inactive")
| bucket _time span=1d
| dedup accountNum accountStatus
| stats count by accountStatus _time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2012 21:29:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63092#M15578</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-13T21:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Relative time and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63093#M15579</link>
      <description>&lt;P&gt;I am indeed working with four different time fields.&lt;/P&gt;

&lt;P&gt;The Target is a constant value (15 = represents the total number of transactions that occur).&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2012 21:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63093#M15579</guid>
      <dc:creator>asarolkar</dc:creator>
      <dc:date>2012-12-13T21:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Relative time and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63094#M15580</link>
      <description>&lt;P&gt;How can there be only 15 transactions total? This is very unclear.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2012 21:37:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63094#M15580</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-13T21:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Relative time and stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63095#M15581</link>
      <description>&lt;P&gt;So the Target number of transactions is 15 - we want to see that as a steady constant in the graph, the rest should be active and inactive.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2012 22:16:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Relative-time-and-stats/m-p/63095#M15581</guid>
      <dc:creator>asarolkar</dc:creator>
      <dc:date>2012-12-13T22:16:32Z</dc:date>
    </item>
  </channel>
</rss>

