<?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: Determine time value based on count and Average duration in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65080#M16103</link>
    <description>&lt;P&gt;I foresee one problem: you cannot create fields in Splunk with names that start with "_". Also, _time is a reserved name, for the timestamp associated with each event.&lt;/P&gt;

&lt;P&gt;Assuming that the eventtype is named "duration" and the actual duration of each call is named &lt;CODE&gt;ms&lt;/CODE&gt; and the method call is named &lt;CODE&gt;Method&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="webmethod" eventtype="duration" 
| stats count as NumCalls avg(ms) as AvgDuration sum(ms) as TotalCost by Method
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, if you really want to compute the NumCalls * AvgDuration, do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="webmethod" eventtype="duration" 
| stats count as NumCalls avg(ms) as AvgDuration sum(ms) as TotalCost by Method
| eval TotalCost = NumCalls * AvgDuration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 15 Dec 2012 09:37:18 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2012-12-15T09:37:18Z</dc:date>
    <item>
      <title>Determine time value based on count and Average duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65078#M16101</link>
      <description>&lt;P&gt;This may not be possible but I work at a SAAS company and we want to start evaluating which of our web methods that are chewing up our web resources on a consistent basis. We have built an event type (_time) that spits out the duration in ms of each method call (_method) for every call.&lt;/P&gt;

&lt;P&gt;So what we would like to do is measure the overall "cost" in time duration of each call by multiplying the average time per call by the count of calls in a specific time period.  Is there a way to generate a table in splunk that shows avg duration, count of method calls, and cost (avgduration X count)? In other words is there a way to multiply the values in two different columns by each other to get a third column&lt;/P&gt;

&lt;P&gt;I guess the query would look something like this:&lt;BR /&gt;
index="webmethod" eventtype="duration" | stats avg(_time), count(_time), (avg(_time) * count(_time) by Method&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:58:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65078#M16101</guid>
      <dc:creator>jericksonpf</dc:creator>
      <dc:date>2020-09-28T12:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: Determine time value based on count and Average duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65079#M16102</link>
      <description>&lt;P&gt;Most definitely, but first of all it's important to know that your choice of field names is kind of dangerous if you want sensible results. &lt;CODE&gt;_time&lt;/CODE&gt; is Splunk's own internal field for event timestamps, so if you overwrite that at search-time you can get into all kinds of weird behaviour. If you're lucky things might come out right in the end but they might as well not. I suggest you use another name for that field - pretty much any other field name than &lt;CODE&gt;_time&lt;/CODE&gt; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; In general, fields starting with &lt;CODE&gt;_&lt;/CODE&gt; are considered to be Splunk's internal fields and are treated a bit differently than "normal" fields, so the best thing to do is not to use leading underscores in your own field names.&lt;/P&gt;

&lt;P&gt;So, let's say your fields are instead called &lt;CODE&gt;duration&lt;/CODE&gt; and &lt;CODE&gt;method&lt;/CODE&gt;. The thing with &lt;CODE&gt;stats&lt;/CODE&gt; here is that you NEED to use some kind of statistical function, so you can't just multiply things directly. You can use &lt;CODE&gt;eval&lt;/CODE&gt; statements inside that statistical function, but those &lt;CODE&gt;eval&lt;/CODE&gt; statements in turn cannot themselves perform statistical functions, so it's a bit of a catch 22 situation.&lt;/P&gt;

&lt;P&gt;You can however first calculate the statistics you want using &lt;CODE&gt;eventstats&lt;/CODE&gt;, and then use those values in a separate &lt;CODE&gt;eval&lt;/CODE&gt; statement. &lt;CODE&gt;eventstats&lt;/CODE&gt; works very much like &lt;CODE&gt;stats&lt;/CODE&gt; except it allows you to do stats "inline" without losing any information to other commands further along the search pipeline.&lt;/P&gt;

&lt;P&gt;So, to sum up, something like this should do (I use first as a stats function here because it's a simple way of getting the unique value that's been calculated per method):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="webmethod" eventtype="duration" | eventstats avg(duration) as avgduration, count by method | eval cost=avgduration*count | stats avg(duration), count, first(cost) as cost by method
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could also do a &lt;CODE&gt;| dedup method | table avgduration count cost&lt;/CODE&gt; at the end if you like that approach more.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Dec 2012 09:31:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65079#M16102</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-12-15T09:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Determine time value based on count and Average duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65080#M16103</link>
      <description>&lt;P&gt;I foresee one problem: you cannot create fields in Splunk with names that start with "_". Also, _time is a reserved name, for the timestamp associated with each event.&lt;/P&gt;

&lt;P&gt;Assuming that the eventtype is named "duration" and the actual duration of each call is named &lt;CODE&gt;ms&lt;/CODE&gt; and the method call is named &lt;CODE&gt;Method&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="webmethod" eventtype="duration" 
| stats count as NumCalls avg(ms) as AvgDuration sum(ms) as TotalCost by Method
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, if you really want to compute the NumCalls * AvgDuration, do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="webmethod" eventtype="duration" 
| stats count as NumCalls avg(ms) as AvgDuration sum(ms) as TotalCost by Method
| eval TotalCost = NumCalls * AvgDuration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Dec 2012 09:37:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65080#M16103</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-15T09:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Determine time value based on count and Average duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65081#M16104</link>
      <description>&lt;P&gt;Not that it matters, but why use avgduration*count when you can just sum up the individual durations ?&lt;/P&gt;</description>
      <pubDate>Sat, 15 Dec 2012 13:06:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65081#M16104</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2012-12-15T13:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Determine time value based on count and Average duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65082#M16105</link>
      <description>&lt;P&gt;This worked great Thanks!&lt;/P&gt;

&lt;P&gt;index="webmethod" eventtype="duration" &lt;BR /&gt;
| stats count as NumCalls avg(ms) as AvgDuration sum(ms) as TotalCost by Method&lt;BR /&gt;
| eval TotalCost = NumCalls * AvgDuration&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 20:00:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65082#M16105</guid>
      <dc:creator>jericksonpf</dc:creator>
      <dc:date>2012-12-17T20:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Determine time value based on count and Average duration</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65083#M16106</link>
      <description>&lt;P&gt;Oops, you could change the second option to&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index="webmethod" eventtype="duration" &lt;BR /&gt;
| stats count as NumCalls avg(ms) as AvgDuration  by Method&lt;BR /&gt;
| eval TotalCost = NumCalls * AvgDuration&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Though it seems like the first option would be more efficient...&lt;/P&gt;</description>
      <pubDate>Mon, 17 Dec 2012 21:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-time-value-based-on-count-and-Average-duration/m-p/65083#M16106</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-17T21:57:43Z</dc:date>
    </item>
  </channel>
</rss>

