<?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: Calculating latency based on uuid in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323088#M60168</link>
    <description>&lt;P&gt;Following should give you duration between request and response. If there are more than two events for a particular request_uuid and session_id, then min(client_timestamp) should give you request time and max(client_timestamp) should give you response time. You can also try first() and last() instead of min() and max().&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=latency_logs  session_id=* (device_name="Device *" OR action="response_received")
| stats count as eventcount min(client_timestamp) as requestTime max(client_timestamp) as responseTime values(device_name) as device_name values(action) as action by request_uuid, session_id
| where eventcount=2 AND isnotnull(action)
| eval duration = responseTime - requestTime 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;BR /&gt;
- Your transaction seems to be a combination of request_uuid and session_id so I have used both in stats query.&lt;BR /&gt;
- Your last example seems to be having request_uuid from second last event and session_id from first event. Seems confusing or maybe incorrect.&lt;BR /&gt;
- You can use fieldformat on requestTime and responseTime to show Time in Human readable format and also capture values(location) as location to show location information in final result.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 15:02:42 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-29T15:02:42Z</dc:date>
    <item>
      <title>Calculating latency based on uuid</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323086#M60166</link>
      <description>&lt;P&gt;I'm trying to calculate request times for a web app to analyze latency. When a user clicks a button in the client UI, I save the time stamp and push that to Splunk (client_timestamp). When the server receives the request it writes a spunk log entry. So event timestamp minus client_timestamp gives me one piece. However, when the server receives the request, it does a few other things before it responds to the client. So when the client receives a response we also log that (action="response_received"). I basically want to find the diff between when the user clicked the UI and when the UI received the signal to write the action="response_received" log.&lt;/P&gt;

&lt;P&gt;[1500700837] location="Germany", device_name="Device A", request_uuid="000412fc-23b9-4882-8241-31482e1987fa", client_timestamp="1500700835936", session_id="8d2c288374d51b6b052e3f03d037b3ca"&lt;BR /&gt;
[1500700837] location="Germany", device_name="Device B", request_uuid="7ad4b1ca-397a-46a6-8bf2-3e97864ffd45", client_timestamp="1500700835936", session_id="5ca03696a0e19c2b89a189e7534ff0b5"&lt;BR /&gt;
[1500673343] type="frontend", action="response_received", request_uuid="000412fc-23b9-4882-8241-31482e1987fa", client_timestamp="1500673347109", session_id="8d2c288374d51b6b052e3f03d037b3ca"&lt;BR /&gt;
[1500700837] location="Canada", device_name="Device C", request_uuid="7ad4b1ca-397a-46a6-8bf2-3e97864ffd45", client_timestamp="1500700835936", session_id="030799a2-9a15-4995-ba1b-04908e1b726b"&lt;BR /&gt;
[1500673343] type="frontend", action="response_received", request_uuid="7ad4b1ca-397a-46a6-8bf2-3e97864ffd45", client_timestamp="1500673347109", session_id="8d2c288374d51b6b052e3f03d037b3ca"&lt;/P&gt;

&lt;P&gt;I essentially want to filter out all the events where not exactly two entries with the same request_uuid exists. Something like:&lt;/P&gt;

&lt;P&gt;sourcetype=latency_logs | stats count by request_uuid&lt;/P&gt;

&lt;P&gt;Now for all where request_uuid exists 2 times, I'd like to take the client_timestamp from the event that has action="response_received" and subtract it from the other event with the same request_uuid.&lt;/P&gt;

&lt;P&gt;Any suggestions how to achieve this? The final result would be a list of request_uuids and their client_timestamp diff&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:00:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323086#M60166</guid>
      <dc:creator>smiehe</dc:creator>
      <dc:date>2020-09-29T15:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating latency based on uuid</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323087#M60167</link>
      <description>&lt;P&gt;This should work for those with exactly two with the same &lt;CODE&gt;request_uuid&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=latency_log | transaction request_uuid | search linecount=2 | eval latency=tonumber(mvindex(client_timestamp,1))-tonumber(mvindex(client_timestamp,0)) | table request_uuid, latency
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to get it for those with 3 or more, as well, then that is not much more difficult:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=latency_log | transaction request_uuid | search linecount&amp;gt;1 | eval cnt=tonumber(mvcount(client_timestamp)) | eval latency=tonumber(mvindex(client_timestamp,cnt-1))-tonumber(mvindex(client_timestamp,0)) | table request_uuid, latency
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you need to make sure that you only count the ones with a &lt;CODE&gt;response_received&lt;/CODE&gt; in case you have some that have not yet been completed, but there are more than one with the same &lt;CODE&gt;request_uuid&lt;/CODE&gt;, use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=latency_log | transaction request_uuid | search linecount&amp;gt;1 | search response_received | eval cnt=tonumber(mvcount(client_timestamp)) | eval latency=tonumber(mvindex(client_timestamp,cnt-1))-tonumber(mvindex(client_timestamp,0)) | table request_uuid, latency
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this would answer all additional questions, in case you need more refined results. &lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 14:43:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323087#M60167</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-07-22T14:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating latency based on uuid</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323088#M60168</link>
      <description>&lt;P&gt;Following should give you duration between request and response. If there are more than two events for a particular request_uuid and session_id, then min(client_timestamp) should give you request time and max(client_timestamp) should give you response time. You can also try first() and last() instead of min() and max().&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=latency_logs  session_id=* (device_name="Device *" OR action="response_received")
| stats count as eventcount min(client_timestamp) as requestTime max(client_timestamp) as responseTime values(device_name) as device_name values(action) as action by request_uuid, session_id
| where eventcount=2 AND isnotnull(action)
| eval duration = responseTime - requestTime 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;BR /&gt;
- Your transaction seems to be a combination of request_uuid and session_id so I have used both in stats query.&lt;BR /&gt;
- Your last example seems to be having request_uuid from second last event and session_id from first event. Seems confusing or maybe incorrect.&lt;BR /&gt;
- You can use fieldformat on requestTime and responseTime to show Time in Human readable format and also capture values(location) as location to show location information in final result.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:02:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-latency-based-on-uuid/m-p/323088#M60168</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T15:02:42Z</dc:date>
    </item>
  </channel>
</rss>

