<?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 How to count events in a time frame based on a time elapsed field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601022#M209194</link>
    <description>&lt;P&gt;&lt;STRONG&gt;What is the is the best approach to creating a field that shows the number of incomplete requests in a given period of time?&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For the machine in question, events are logged when it completes the Request-Response Loop.&amp;nbsp; &amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I have a field `time_taken` which shows, in milliseconds, how long the Request-Response Loop has taken.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I have already done the following, now how do I evaluate the total number of `open_requests`&amp;nbsp; for each second?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval responded = _time
| eval requested = _time - time_taken

| eval responded = strftime(responded ,"%Y/%m/%d %H:%M:%S")
| eval requested = strftime(requested ,"%Y/%m/%d %H:%M:%S")

| eval open_requests = ??? 

| table _time open_requests
| sort - _time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2022 13:58:06 GMT</pubDate>
    <dc:creator>CarbonCriterium</dc:creator>
    <dc:date>2022-06-08T13:58:06Z</dc:date>
    <item>
      <title>How to count events in a time frame based on a time elapsed field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601022#M209194</link>
      <description>&lt;P&gt;&lt;STRONG&gt;What is the is the best approach to creating a field that shows the number of incomplete requests in a given period of time?&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For the machine in question, events are logged when it completes the Request-Response Loop.&amp;nbsp; &amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I have a field `time_taken` which shows, in milliseconds, how long the Request-Response Loop has taken.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I have already done the following, now how do I evaluate the total number of `open_requests`&amp;nbsp; for each second?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval responded = _time
| eval requested = _time - time_taken

| eval responded = strftime(responded ,"%Y/%m/%d %H:%M:%S")
| eval requested = strftime(requested ,"%Y/%m/%d %H:%M:%S")

| eval open_requests = ??? 

| table _time open_requests
| sort - _time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 13:58:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601022#M209194</guid>
      <dc:creator>CarbonCriterium</dc:creator>
      <dc:date>2022-06-08T13:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to count events in a time frame based on a time elapsed field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601051#M209206</link>
      <description>&lt;P&gt;It looks like the challenge is how to define the requirement, i.e., the difference between _time at the beginning of the pseudo code which you use as a marker of "responded", and _time at the end of the pseudo code which you intend as a marker of clock unit (second).&lt;/P&gt;&lt;P&gt;I assume that fields _time and time_taken, therefore responded and requested as well, are all in time format, i.e., can be used in numeric comparisons. &amp;nbsp;Ignoring the strftime() calculations which are meant for display only, the following can give you something meaningful:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval responded = _time
| eval requested = _time - time_taken
| bin _time span=1s ``` chop _time into 1-s bins ```
| where requested &amp;lt; _time AND time_taken &amp;gt; 1s ``` many ways to construct this, depending on interpretation and preference ```
| timechart count&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 16:07:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601051#M209206</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-06-08T16:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to count events in a time frame based on a time elapsed field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601083#M209218</link>
      <description>&lt;P&gt;Thanks, I eventually came to something similar!&amp;nbsp; I think this is the solution I am after, unless you can spot a hole in the logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval seconds_taken = time_taken/1000
| eval responded = _time, requested = _time - seconds_taken
| where requested &amp;lt;= responded AND seconds_taken &amp;gt; 0
``` | where requested &amp;lt;= responded AND seconds_taken &amp;gt;= 0 ```
| timechart count span=1s&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 21:44:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601083#M209218</guid>
      <dc:creator>CarbonCriterium</dc:creator>
      <dc:date>2022-06-08T21:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to count events in a time frame based on a time elapsed field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601182#M209243</link>
      <description>&lt;P&gt;As long as you test a variety of data manually and are satisfied with the results, there should be no concern.&lt;/P&gt;&lt;P&gt;This said, both conditions "requested &amp;lt;= responded" and "seconds_taken &amp;gt; 0" will always be true. &amp;nbsp;Shouldn't it be "seconds_taken &amp;gt; 1"? ("requested &amp;lt;= responded" is always true.) &amp;nbsp;At the bottom of this, any event in which time_taken &amp;gt; 1000 would be characterized as "open request" because you wanted to count from the end of each second.&lt;/P&gt;&lt;P&gt;To get the results logically sound, you also want to shift time axis according to requested, something like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval seconds_taken = time_taken/1000
| eval responded = _time, requested = _time - seconds_taken
| where seconds_taken &amp;gt; 1
| rename requested AS _time
| timechart count span=1s&lt;/LI-CODE&gt;&lt;P&gt;On the other hand, now that I look it from this angle, there's another consideration that needs attention: If an event's seconds_taken &amp;gt; 2 but &amp;lt; 3, the event should be counted as "open request" in two 1s bins; the "open" state will be concurrent with other "open" requests (older and newer) for the entire duration. &amp;nbsp;Effectively, you would be stacking Gantt charts.&lt;/P&gt;&lt;P&gt;I faced a very similar problem years ago that somesoni2 helped solve. &amp;nbsp;You can see the answer in&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/How-to-compute-concurrent-members-in-events/m-p/112163#M29438" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/How-to-compute-concurrent-members-in-events/m-p/112163#M29438&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 11:51:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-events-in-a-time-frame-based-on-a-time-elapsed/m-p/601182#M209243</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-06-09T11:51:59Z</dc:date>
    </item>
  </channel>
</rss>

