<?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 to calculate average of value pairs within a field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248419#M74139</link>
    <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query |mvexpand init_time|stats avg(init_time) by T
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Lp&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2015 15:10:40 GMT</pubDate>
    <dc:creator>lpolo</dc:creator>
    <dc:date>2015-09-29T15:10:40Z</dc:date>
    <item>
      <title>How to calculate average of value pairs within a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248418#M74138</link>
      <description>&lt;P&gt;I need to extract value pairs from a field (string=integer) and then calculate the average of each of the strings. &lt;/P&gt;

&lt;P&gt;The field in question looks like this&lt;BR /&gt;
… [T=76ms,Rquest1=1, Request2=70, Request3=100, Request10=7]&lt;BR /&gt;
… [T=134ms,Rquest1=11, Request7=700, Request8=1]&lt;/P&gt;

&lt;P&gt;The query I am using looks something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;filters such as earliest=-1m&amp;gt; | makemv tokenizer="(.+?)(?=,|$),?" views   | rex field=filtered_views "(?&amp;lt;int_call&amp;gt;.*)=(?&amp;lt;int_time&amp;gt;.*)" | table T, int_call, int_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That gives me the output on the attached image &lt;IMG src="https://community.splunk.com/storage/temp/62251-splunktable.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;I want the average of Rquest1, Request2, Request3, etc. &lt;/P&gt;

&lt;P&gt;The content comes from an app server log and the strings are calls to inner processes that happen for a particular request. That means that the strings can vary and there is not a comprehensive, stable list of values I can use to match as suggested on &lt;A href="https://answers.splunk.com/answers/6966/how-can-i-manipulate-an-extracted-field-with-a-numerical-component-and-a-text-component.html" target="_blank"&gt;Question 6966&lt;/A&gt; or &lt;A href="https://answers.splunk.com/answers/45993/aggregating-field-values.html" target="_blank"&gt;Question 45993&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Note that I can remove T to simplify the request, but the values on int_call and int_time will remain as groups, not as individual fields&lt;BR /&gt;
Thank you in advance. This is eating my brain out.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248418#M74138</guid>
      <dc:creator>maalvare</dc:creator>
      <dc:date>2020-09-29T07:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average of value pairs within a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248419#M74139</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query |mvexpand init_time|stats avg(init_time) by T
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Lp&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 15:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248419#M74139</guid>
      <dc:creator>lpolo</dc:creator>
      <dc:date>2015-09-29T15:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average of value pairs within a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248420#M74140</link>
      <description>&lt;P&gt;Try something like this (lines before extract is just get a dataset with your sample data, replace it with your base search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval temp="… [T=76ms,Request1=1, Request2=70, Request3=100, Request10=7]#… [T=134ms,Request1=11, Request7=700, Request8=1]" | table temp | makemv temp delim="#" | mvexpand temp | rename temp as _raw
| extract kvdelim="=:" pairdelim=",]" | stats avg(Request*) as Request*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2015 15:26:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248420#M74140</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-29T15:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average of value pairs within a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248421#M74141</link>
      <description>&lt;P&gt;Thank you for the answers. &lt;/P&gt;

&lt;P&gt;@Ipolo answer was very close to what I needed. I simply added by int_call as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;filters such as earliest=-1m&amp;gt; | makemv tokenizer="(.+?)(?=,|$),?" views   | rex field=filtered_views "(?&amp;lt;int_call&amp;gt;.*)=(?&amp;lt;int_time&amp;gt;.*)" | mvexpand init_time|stats avg(int_time) by int_call
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;@somesoni2 Your query is very interesting and I would like to play more with t. However, it seems I would have to know the fields to populate tepm, isn't? or I just simply paste my filtered_views in there? I could not get it to work so I wanted to clarify&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 12:37:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-value-pairs-within-a-field/m-p/248421#M74141</guid>
      <dc:creator>maalvare</dc:creator>
      <dc:date>2015-09-30T12:37:39Z</dc:date>
    </item>
  </channel>
</rss>

