<?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 do you calculate average time between transaction groups by two fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436442#M124393</link>
    <description>&lt;P&gt;Try something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="index" sourcetype="sourcetype" ("SUBSCRIBE" OR "NOTIFY")
| rename COMMENT as "sort into ascending _time order"
| sort 0 _time 

| rename COMMENT as "copy down the prior _time value for the same peer_name and resource."
| streamstats current=f last(_time) as prevtime by peer_name resource

| rename COMMENT as "calculate the difference, then calculate the average difference."
| eval stepduration = _time - prevtime
| stats avg(stepduration) as ratio by peer_name resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;You might also do time trials using this sort instead and see if it makes it faster or slower.  I would bet on marginally faster, but the result can be highly data dependent.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename COMMENT as "sort into ascending _time order"
| sort 0 _time peer_name resource

| rename COMMENT as "copy down the prior _time value for the same peer_name and resource."
| streamstats reset_on_change=t current=f last(_time) as prevtime by peer_name resource

| rename COMMENT as "calculate the difference, then calculate the average difference."
| eval stepduration = _time - prevtime
| stats avg(stepduration) as ratio by peer_name resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;In both cases above, the first record of each set will have prevtime as null, thus there will be no difference to calculate.  The average will thus be correct.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Aug 2018 02:46:16 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2018-08-31T02:46:16Z</dc:date>
    <item>
      <title>How do you calculate average time between transaction groups by two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436441#M124392</link>
      <description>&lt;P&gt;I have logs from a SIP proxy server and I'm trying to get metrics from SIP transactions metrics from a  SIP proxy server logs.&lt;BR /&gt;
I have the following events:&lt;/P&gt;

&lt;P&gt;Peer AAA events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time, call id A,  message A.1,  peer_name "AAA", resource "111"
Time, call id A,  message A.2,  peer_name "AAA", resource "111"
Time, call id A,  message A.3,  peer_name "AAA", resource "111"

Time, call id C,  message C.1,  peer_name "AAA", resource "112"
Time, call id C,  message C.2,  peer_name "AAA", resource "112"
Time, call id C,  message C.3,  peer_name "AAA", resource "112"

Time, call id I,  message I.1,  peer_name "AAA", resource "111"
Time, call id I,  message I.2,  peer_name "AAA", resource "111"
Time, call id I,  message I.3,  peer_name "AAA", resource "111"

Time, call id J,  message J.1,  peer_name "AAA", resource "112"
Time, call id J,  message J.2,  peer_name "AAA", resource "112"
Time, call id J,  message J.3,  peer_name "AAA", resource "112"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(...)&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Peer BBB events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time, call id B,  message B.1,  peer_name "BBB", resource "111"
Time, call id B,  message B.2,  peer_name "BBB", resource "111"
Time, call id B,  message B.3,  peer_name "BBB", resource "111"

Time, call id D,  message D.1,  peer_name "BBB", resource "112"
Time, call id D,  message D.2,  peer_name "BBB", resource "112"
Time, call id D,  message D.3,  peer_name "BBB", resource "112"

Time, call id F,  message F.1,  peer_name "BBB", resource "111"
Time, call id F,  message F.2,  peer_name "BBB", resource "111"
Time, call id F,  message F.3,  peer_name "BBB", resource "111"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(...)&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Peer CCC events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time, call id E,  message E.1,  peer_name "CCC", resource "113"
Time, call id E,  message E.2,  peer_name "CCC", resource "113"
Time, call id E,  message E.3,  peer_name "CCC", resource "113"

Time, call id G,  message G.1,  peer_name "CCC", resource "114"
Time, call id G, message G.2,  peer_name "CCC", resource "114"
Time, call id G, message G.3,  peer_name "CCC", resource "114"

Time, call id H,  message H.1,  peer_name "CCC", resource "113"
Time, call id H,  message H.2,  peer_name "CCC", resource "113"
Time, call id H,  message H.3,  peer_name "CCC", resource "113"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(...)&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Notes: &lt;BR /&gt;
- All peer can have N resources.&lt;BR /&gt;
- Different peers can have the same name resource&lt;BR /&gt;
- Exists N different peers.&lt;BR /&gt;
- In the timeline, messages from different peers may be mixed. &lt;/P&gt;

&lt;P&gt;Order in Timeline (only show AAA and BBB messages to simplify):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1. Time, call id A,  message A.1,  peer_name "AAA", resource "111"
2. Time, call id B,  message B.1,  peer_name "BBB", resource "111"
3. Time, call id C,  message C.1,  peer_name "AAA", resource "112"
4. Time, call id A,  message A.2,  peer_name "AAA", resource "111"
5. 7. Time, call id A,  message A.3,  peer_name "AAA", resource "111"
6. Time, call id D,  message D.1,  peer_name "BBB", resource "112"
7. Time, call id I,  message I.1,  peer_name "AAA", resource "111"
8. Time, call id B,  message B.2,  peer_name "BBB", resource "111"
9. Time, call id I,  message I.2,  peer_name "AAA", resource "111"
10. Time, call id C,  message C.2,  peer_name "AAA", resource "112"
11. Time, call id C,  message C.3,  peer_name "AAA", resource "112"
12. Time, call id J,  message J.1,  peer_name "AAA", resource "112"
13. Time, call id B,  message B.3,  peer_name "BBB", resource "111"
14. 4. Time, call id F,  message F.1,  peer_name "BBB", resource "111"
15. Time, call id F,  message F.2,  peer_name "BBB", resource "111"
16. Time, call id I,  message I.3,  peer_name "AAA", resource "111"
17. Time, call id J,  message J.2,  peer_name "AAA", resource "112"
18. Time, call id D,  message D.2,  peer_name "BBB", resource "112"
19. Time, call id D,  message D.3,  peer_name "BBB", resource "112"
20. Time, call id J,  message J.3,  peer_name "AAA", resource "112"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My goal is to know the average time between transactions from the same peer / resource.&lt;BR /&gt;
Peer AAA and resource 111:&lt;BR /&gt;
- Call id A, peer AAA, resource 111&lt;BR /&gt;
- Call id I, peer AAA, resource 111&lt;BR /&gt;
- Call id ..., peer AAA, resource 111&lt;/P&gt;

&lt;P&gt;Peer AAA and resource 112:&lt;BR /&gt;
- Call id C, peer AAA, resource 112&lt;BR /&gt;
- Call id J, peer AAA, resource 112&lt;BR /&gt;
- Call id ..., peer AAA, resource 112&lt;/P&gt;

&lt;P&gt;Peer BBB and resource 112:&lt;BR /&gt;
- Call id B, peer BBB, resource 111&lt;BR /&gt;
- Call id F, peer BBB, resource 111&lt;BR /&gt;
(...)&lt;/P&gt;

&lt;P&gt;At the end I would like to get a table with:&lt;BR /&gt;
|| Peer || Resource || Avg (time) bettween different transactions) ||&lt;BR /&gt;
|| AAA  || 111           || 2s                                                                          ||&lt;BR /&gt;
|| AAA  || 112           || 3,5s                                                                       ||&lt;BR /&gt;
|| BBB  || 111           || 1s                                                                          ||&lt;BR /&gt;
|| BBB  || 112           || 5s .                                                                        ||&lt;BR /&gt;
|| CCC  || 113           || 1s                                                                          ||&lt;BR /&gt;
|| CCC  || 114           || 5s .                                                                        ||&lt;/P&gt;

&lt;P&gt;I created a query that give almost what I want but only if I limit to a specific peer and resource. Otherwise the query does not pay attention to transactions per peer and resource and calculates the difference between all transactions.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index" sourcetype="sourcetype" ("SUBSCRIBE" OR "NOTIFY")
| transaction call_id maxspan=3s
| eval success=if(searchmatch("404"),1,0)
| where success=1
| &amp;lt;extract peer_name&amp;gt;
| extract resource&amp;gt;
| where peer_name="ABC"
| where resource="123"
| eval initial_time=_time
| autoregress _time AS previous_time 
| delta previous_time AS difference
| chart avg(difference) AS ratio BY peer_name resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;|| field1  ||   flied 2 || avg time                     ||&lt;BR /&gt;
| ABC        | 123         | -5.031163865546219 | &lt;/P&gt;

&lt;P&gt;Any ideas?&lt;BR /&gt;
Using Splunk 7.0.3.4 version. &lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 16:13:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436441#M124392</guid>
      <dc:creator>rparadinha</dc:creator>
      <dc:date>2018-08-30T16:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate average time between transaction groups by two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436442#M124393</link>
      <description>&lt;P&gt;Try something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="index" sourcetype="sourcetype" ("SUBSCRIBE" OR "NOTIFY")
| rename COMMENT as "sort into ascending _time order"
| sort 0 _time 

| rename COMMENT as "copy down the prior _time value for the same peer_name and resource."
| streamstats current=f last(_time) as prevtime by peer_name resource

| rename COMMENT as "calculate the difference, then calculate the average difference."
| eval stepduration = _time - prevtime
| stats avg(stepduration) as ratio by peer_name resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;You might also do time trials using this sort instead and see if it makes it faster or slower.  I would bet on marginally faster, but the result can be highly data dependent.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename COMMENT as "sort into ascending _time order"
| sort 0 _time peer_name resource

| rename COMMENT as "copy down the prior _time value for the same peer_name and resource."
| streamstats reset_on_change=t current=f last(_time) as prevtime by peer_name resource

| rename COMMENT as "calculate the difference, then calculate the average difference."
| eval stepduration = _time - prevtime
| stats avg(stepduration) as ratio by peer_name resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;In both cases above, the first record of each set will have prevtime as null, thus there will be no difference to calculate.  The average will thus be correct.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2018 02:46:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436442#M124393</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-08-31T02:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate average time between transaction groups by two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436443#M124394</link>
      <description>&lt;P&gt;@DalJeanis It was exactly what I was looking for.&lt;BR /&gt;
Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2018 09:45:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-average-time-between-transaction-groups-by/m-p/436443#M124394</guid>
      <dc:creator>rparadinha</dc:creator>
      <dc:date>2018-08-31T09:45:10Z</dc:date>
    </item>
  </channel>
</rss>

