<?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 query issue in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416991#M27428</link>
    <description>&lt;P&gt;OKay, there are several things that could be wrong, depending on what your data really is.  Here are my assumptions...&lt;/P&gt;

&lt;P&gt;1) &lt;CODE&gt;rtIOt&lt;/CODE&gt; is a reading of some kind.&lt;BR /&gt;
2) &lt;CODE&gt;tmrtIOc&lt;/CODE&gt; is a timestamp of some kind.&lt;BR /&gt;
3)  There is a&lt;CODE&gt;_time&lt;/CODE&gt; on each record that equates to &lt;CODE&gt;tmrtIOc&lt;/CODE&gt;, and _time is in normal epoch time, no matter what scale &lt;CODE&gt;tmrtIOc&lt;/CODE&gt; might be in.&lt;BR /&gt;
4) You are looking for the difference between successive readings, divided by the difference between successive readings times, in whatever unit is present in each of those fields.&lt;/P&gt;

&lt;P&gt;If all the above assumptions hold, then the following should get you what you want...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=$indx$ nodeIdStr=$selswitch$
| fields _time, nodeIdStr, rtIOt, tmrtIOc, sid, did, lun
| eval combination=sid."-".did."-".lun
| sort 0 combination, tmrtIOc
| streamstats current=f last(rtIOt) as last_rtio last(tmrtIOc) as last_tmrtIOc by combination
| eval diffrtio =  coalesce(rtIOt - last_rtio,0) 
| eval difftmrtIOc =  coalesce(tmrtIOc - last_tmrtIOc,1)
| eval res = diffrtio / difftmrtIOc
| timechart span=30  avg(res) as AVG  usenull=f by combination
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Items to note - &lt;/P&gt;

&lt;P&gt;1) You can do multiple aggregate commands in a &lt;CODE&gt;streamstats&lt;/CODE&gt; at one pass.&lt;/P&gt;

&lt;P&gt;2) Make sure to code the &lt;CODE&gt;0&lt;/CODE&gt; in &lt;CODE&gt;| sort 0 ...your sort fields...&lt;/CODE&gt;.  &lt;CODE&gt;Sort&lt;/CODE&gt;, in splunk, is a transforming command that defaults to limit the number of results to 100.   You need the 0 to have it return all values.&lt;/P&gt;

&lt;P&gt;3) Difference will be null for the first record of each combination, since there was no prior event.  By defaulting the reading difference to 0, and the time difference to 1, we achieve a start at 0 at the beginning of the report.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2018 19:04:15 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2018-08-21T19:04:15Z</dc:date>
    <item>
      <title>streamstats query issue</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416988#M27425</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=$indx$ nodeIdStr=$selswitch$ |sort _time,rtIOt|fields nodeIdStr,sid,did,lun,rtIOt,tmrtIOc|
fields _time,nodeIdStr,rtIOt, tmrtIOc, sid, did, lun|eval combination=sid."-".did."-".lun|eval timediff=tmrtIOc| 
streamstats current=f last(rtIOt) as last_rtio by combination | rename rtIOt as current_rtio | eval diffrtio =  current_rtio -last_rtio 
|eval res=diffrtio/timediff | timechart span=30  avg(res) as AVG  usenull=f by combination
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am using this query above which finds difference between two rtIOt between two events, but in each event has "tmrtIOc" also.&lt;BR /&gt;
I need to find the difference of tmrtIOc as well in the same query. I tried like below but it didnt work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=$indx$ nodeIdStr=$selswitch$ |sort _time,rtIOt|fields nodeIdStr,sid,did,lun,rtIOt,tmrtIOc|
fields _time,nodeIdStr,rtIOt, tmrtIOc, sid, did, lun|eval combination=sid."-".did."-".lun|eval timediff=tmrtIOc| 
streamstats current=f last(rtIOt) as last_rtio by combination | rename rtIOt as current_rtio | eval diffrtio =  current_rtio -last_rtio |
streamstats current=f last(tmrtIOc) as last_tmIOc by combination | rename tmrtIOc as current_tmIOc | eval difftmIOc =  current_tmIOc -last_tmIOc |eval res=diffrtio/timediff | timechart span=30  avg(res) as AVG  usenull=f by combination
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried below one also:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=$indx$ nodeIdStr=$selswitch$ |sort _time,rtIOt|fields nodeIdStr,sid,did,lun,rtIOt,tmrtIOc|
fields _time,nodeIdStr,rtIOt, tmrtIOc, sid, did, lun|eval combination=sid."-".did."-".lun|eval timediff=tmrtIOc| 
streamstats current=f last(rtIOt) as last_rtio,last(tmrtIOc) as last_tmIOc by combination | rename rtIOt as current_rtio|rename tmrtIOc as current_tmIOc | eval diffrtio =  current_rtio -last_rtio |  eval difftmIOc =  current_tmIOc -last_tmIOc|eval res=diffrtio/timediff | timechart span=30  avg(res) as AVG  usenull=f by combination
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 10:39:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416988#M27425</guid>
      <dc:creator>sawgata12345</dc:creator>
      <dc:date>2018-08-21T10:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats query issue</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416989#M27426</link>
      <description>&lt;P&gt;@sawgata12345, whats the problem/error/wrong in the result?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 13:17:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416989#M27426</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-21T13:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats query issue</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416990#M27427</link>
      <description>&lt;P&gt;what, exactly, is &lt;CODE&gt;tmrtIOc&lt;/CODE&gt;, and what exactly is &lt;CODE&gt;tfIOt&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 18:52:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416990#M27427</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-08-21T18:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats query issue</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416991#M27428</link>
      <description>&lt;P&gt;OKay, there are several things that could be wrong, depending on what your data really is.  Here are my assumptions...&lt;/P&gt;

&lt;P&gt;1) &lt;CODE&gt;rtIOt&lt;/CODE&gt; is a reading of some kind.&lt;BR /&gt;
2) &lt;CODE&gt;tmrtIOc&lt;/CODE&gt; is a timestamp of some kind.&lt;BR /&gt;
3)  There is a&lt;CODE&gt;_time&lt;/CODE&gt; on each record that equates to &lt;CODE&gt;tmrtIOc&lt;/CODE&gt;, and _time is in normal epoch time, no matter what scale &lt;CODE&gt;tmrtIOc&lt;/CODE&gt; might be in.&lt;BR /&gt;
4) You are looking for the difference between successive readings, divided by the difference between successive readings times, in whatever unit is present in each of those fields.&lt;/P&gt;

&lt;P&gt;If all the above assumptions hold, then the following should get you what you want...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=$indx$ nodeIdStr=$selswitch$
| fields _time, nodeIdStr, rtIOt, tmrtIOc, sid, did, lun
| eval combination=sid."-".did."-".lun
| sort 0 combination, tmrtIOc
| streamstats current=f last(rtIOt) as last_rtio last(tmrtIOc) as last_tmrtIOc by combination
| eval diffrtio =  coalesce(rtIOt - last_rtio,0) 
| eval difftmrtIOc =  coalesce(tmrtIOc - last_tmrtIOc,1)
| eval res = diffrtio / difftmrtIOc
| timechart span=30  avg(res) as AVG  usenull=f by combination
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Items to note - &lt;/P&gt;

&lt;P&gt;1) You can do multiple aggregate commands in a &lt;CODE&gt;streamstats&lt;/CODE&gt; at one pass.&lt;/P&gt;

&lt;P&gt;2) Make sure to code the &lt;CODE&gt;0&lt;/CODE&gt; in &lt;CODE&gt;| sort 0 ...your sort fields...&lt;/CODE&gt;.  &lt;CODE&gt;Sort&lt;/CODE&gt;, in splunk, is a transforming command that defaults to limit the number of results to 100.   You need the 0 to have it return all values.&lt;/P&gt;

&lt;P&gt;3) Difference will be null for the first record of each combination, since there was no prior event.  By defaulting the reading difference to 0, and the time difference to 1, we achieve a start at 0 at the beginning of the report.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 19:04:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416991#M27428</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-08-21T19:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats query issue</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416992#M27429</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
actually when i am using one streamstats its showing results but as soon as i put a pipe(|) and add one more streamstats for another parameter it shows "No results found"&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 07:45:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416992#M27429</guid>
      <dc:creator>sawgata12345</dc:creator>
      <dc:date>2018-08-24T07:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: streamstats query issue</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416993#M27430</link>
      <description>&lt;P&gt;these are just parameters received in json format.&lt;BR /&gt;
suppose like this&lt;BR /&gt;
{"nodeIdStr":"sw1","sid":"001","did":"0000","lun":"0001","rtIOt":1002,"tmrtIOc":1001000}  lot other parameters are there but only these parameters are required for this query.&lt;BR /&gt;
rtIOt  is float type and its total read time,&lt;BR /&gt;
tmrtIOc is also float type and total bytes transfered during the above read time&lt;BR /&gt;
These both values are cumulative so need to take a difference with streamstats function between two events.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 07:56:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/streamstats-query-issue/m-p/416993#M27430</guid>
      <dc:creator>sawgata12345</dc:creator>
      <dc:date>2018-08-24T07:56:30Z</dc:date>
    </item>
  </channel>
</rss>

