<?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: streamstats event question in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349278#M175212</link>
    <description>&lt;P&gt;woodcock has given you code to pull the timestamp, and suggested the use of delta rather than streamstats for calculating the time difference.  Delta is a great tool, but it needs to be enhanced with a "by field"  option, to make this kind of thing easier.&lt;/P&gt;

&lt;P&gt;Since you are calculating this on a PER USER basis, in a single search, delta is probably too much trouble to work with.   Instead, use ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats avg(requestTimestamp) as avgTimestamp by user window=2
| eval deltaTimestamp = 2*( requestTimestamp -avgTimestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And, before you do the above, you need to convert the timestamp and sort the file by user/timestamp to handle your record order issue..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval requestTimestamp=strptime(requestTimestamp, "%Y - %m - %dT%H: %M: %S.%3N%Z" 
| sort 0 user requestTimestamp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Mar 2017 15:41:45 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-03-09T15:41:45Z</dc:date>
    <item>
      <title>streamstats event question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349276#M175210</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I amb calculating the averge between two consecutive events using streamstats, the question is that I have to do it with a time passed in the event data, see JSON example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
product_name: Native Client
product_version: 1.0.03
userId: serfr342-204S88T05285
value: {
errorDetail:
action: Share
mediaStatistics: {
[ + ]
}
requestTimestamp: 2017 - 03 - 08T03: 47: 49.016Z
}
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;i have to calculate the average in a stream manner between "reqestTimestamp" to "requestTimestamp" for a given user, but I am not sure if streamstats look for that times and sort them in beforehand, it seems is mixing arrival times with this specified time, as I am getting negative values.&lt;/P&gt;

&lt;P&gt;Thanks in advance,&lt;BR /&gt;
Juan&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 11:47:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349276#M175210</guid>
      <dc:creator>jperezes</dc:creator>
      <dc:date>2017-03-09T11:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats event question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349277#M175211</link>
      <description>&lt;P&gt;Like this (NOTE: I am skeptical the whitespace in your sample data is the way that it actually is):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your Base Search Here | eval rTime=strptime(requestTimestamp, "%Y - %m - %dT%H: %M: %S.%3N%Z" | delta rTime AS requestDelta
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 15:10:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349277#M175211</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-09T15:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats event question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349278#M175212</link>
      <description>&lt;P&gt;woodcock has given you code to pull the timestamp, and suggested the use of delta rather than streamstats for calculating the time difference.  Delta is a great tool, but it needs to be enhanced with a "by field"  option, to make this kind of thing easier.&lt;/P&gt;

&lt;P&gt;Since you are calculating this on a PER USER basis, in a single search, delta is probably too much trouble to work with.   Instead, use ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats avg(requestTimestamp) as avgTimestamp by user window=2
| eval deltaTimestamp = 2*( requestTimestamp -avgTimestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And, before you do the above, you need to convert the timestamp and sort the file by user/timestamp to handle your record order issue..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval requestTimestamp=strptime(requestTimestamp, "%Y - %m - %dT%H: %M: %S.%3N%Z" 
| sort 0 user requestTimestamp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 15:41:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/streamstats-event-question/m-p/349278#M175212</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-09T15:41:45Z</dc:date>
    </item>
  </channel>
</rss>

