<?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 write a search to calculate the average and median for a field in my sample data and produce a time chart? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201922#M58557</link>
    <description>&lt;P&gt;You need to extract the field(s) that you want to work with. You could use the interactive field extractor, which would create a permanent field - if you will continue to analyze this data, this would probably be the best option. Or, you could create a temporary field using the &lt;CODE&gt;rex&lt;/CODE&gt; command, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x source=y
| rex "rate-\&amp;gt; (?&amp;lt;rate&amp;gt;\d+)"
| stats avg(rate) as "Average rage" median(rate) as "Median Rate"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x source=y
| rex "rate-\&amp;gt; (?&amp;lt;rate&amp;gt;\d+)"
| timechart span=15ms  avg(rate) as "Average rage" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Dec 2015 00:28:40 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2015-12-29T00:28:40Z</dc:date>
    <item>
      <title>How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201920#M58555</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;

&lt;P&gt;Am using Splunk for the first time.&lt;BR /&gt;
I need to calculate the average and Median for the field &lt;STRONG&gt;rate&lt;/STRONG&gt; which is shown below.&lt;/P&gt;

&lt;P&gt;Here's the sample output from my Splunk log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Thu Dec 17 02:48:52 GMT+00:00 2015 [STATS] bucket-&amp;gt; 6 , 3795 , 25322 , 318 , 240 , 0
Thu Dec 17 02:48:52 GMT+00:00 2015 [STATS] rate-&amp;gt; 7123440
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In  the search text box, I am specifying the &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;index_name&amp;gt; source=&amp;lt;source_name&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;since the above mentioned pattern is not key=value, I am unable to calculate the average and median for it, but I cannot change the pattern since it is existing.  &lt;/P&gt;

&lt;P&gt;How to calculate the average and median of this field? Please kindly help. &lt;/P&gt;

&lt;P&gt;Your timely intervention really helps me  a lot.&lt;/P&gt;

&lt;P&gt;Based on this &lt;STRONG&gt;rate&lt;/STRONG&gt; field, I need to draw a time chart for every 15ms... It will be great if you can share the usage and steps.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2015 23:45:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201920#M58555</guid>
      <dc:creator>nsrao1983</dc:creator>
      <dc:date>2015-12-28T23:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201921#M58556</link>
      <description>&lt;P&gt;Any text that isn't in key=value format can be extracted into a field by developing a &lt;A href="http://docs.splunk.com/Splexicon:Fieldextraction"&gt;field extraction&lt;/A&gt;. Once you have that field extraction created and applied to your sourcetype/source you can then search for all events in your index and source that have a rate field and calculate &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.2/SearchReference/CommonStatsFunctions"&gt;statistics&lt;/A&gt; across all events with this field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;index_name&amp;gt; source=&amp;lt;source_name&amp;gt; rate=* | timechart avg(rate) median(rate)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One of the nice things about Splunk, is you can adjust these extractions at search time, and don't have to worry about reindexing your data. The &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.2/SearchReference/timechart"&gt;timechart&lt;/A&gt; command has a number of options you may be interested in as well, &lt;CODE&gt;span&lt;/CODE&gt; in particular if you need to adjust the bucket sizes.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 00:23:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201921#M58556</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-12-29T00:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201922#M58557</link>
      <description>&lt;P&gt;You need to extract the field(s) that you want to work with. You could use the interactive field extractor, which would create a permanent field - if you will continue to analyze this data, this would probably be the best option. Or, you could create a temporary field using the &lt;CODE&gt;rex&lt;/CODE&gt; command, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x source=y
| rex "rate-\&amp;gt; (?&amp;lt;rate&amp;gt;\d+)"
| stats avg(rate) as "Average rage" median(rate) as "Median Rate"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x source=y
| rex "rate-\&amp;gt; (?&amp;lt;rate&amp;gt;\d+)"
| timechart span=15ms  avg(rate) as "Average rage" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Dec 2015 00:28:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201922#M58557</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-12-29T00:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201923#M58558</link>
      <description>&lt;P&gt;Team,&lt;/P&gt;

&lt;P&gt;Appreciate your prompt response.&lt;/P&gt;

&lt;P&gt;I was unable to see the results by executing the above pattern.&lt;/P&gt;

&lt;P&gt;For your reference am providing the sample output in logs for more clarity.&lt;/P&gt;

&lt;P&gt;See the below output in my logs&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Thu Dec 17 02:48:37 GMT+00:00 2015&lt;/STRONG&gt; [STATS] rate-&amp;gt; &lt;STRONG&gt;7549440&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;Thu Dec 17 02:48:52 GMT+00:00 2015&lt;/STRONG&gt; [STATS] rate-&amp;gt; &lt;STRONG&gt;7123440&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;Thu Dec 17 02:49:07 GMT+00:00 2015&lt;/STRONG&gt; [STATS] rate-&amp;gt; &lt;STRONG&gt;6730800&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;Thu Dec 17 02:49:22 GMT+00:00 2015&lt;/STRONG&gt; [STATS] rate-&amp;gt; &lt;STRONG&gt;7172400&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;Thu Dec 17 02:49:37 GMT+00:00 2015&lt;/STRONG&gt; [STATS] &lt;STRONG&gt;rate-&amp;gt; 0&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;For every 15 milli secs some value will be printed against  the "rate"&lt;/P&gt;

&lt;P&gt;I need to calculate the following&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;Average and Median for rate&lt;BR /&gt;
(After rate either 0 or some number will be there always and no spaces.)&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Timechart against the rate and time. (for every 15millisecs, we are printing the time and rate which is shown above. We need to plot the graph using the splunk for the same)&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;index=x source=y   &lt;/P&gt;

&lt;P&gt;It will a great help if you can provide the inputs to achieve the above two targets. So that we can start using the spunk in an extensive way&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 01:21:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201923#M58558</guid>
      <dc:creator>nsrao1983</dc:creator>
      <dc:date>2015-12-29T01:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201924#M58559</link>
      <description>&lt;P&gt;This regular expression &lt;CODE&gt;"rate-\&amp;gt; (?\d+)"&lt;/CODE&gt; has a space after the &lt;CODE&gt;&amp;gt;&lt;/CODE&gt;. If your data doesn't have a space, use this regular expression instead&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;"rate-\&amp;gt;(?\d+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;HTH&lt;/P&gt;

&lt;P&gt;If you need to create fields in order to use Splunk "in an extensive way," I recommend that you review the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchTutorial/WelcometotheSearchTutorial"&gt;Splunk Search Tutorial&lt;/A&gt;, particularly this section: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchTutorial/Usefieldstosearch"&gt;Use fields to search&lt;/A&gt;. You should also read the documentation on the  &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.2/Knowledge/ExtractfieldsinteractivelywithIFX"&gt;field extractor&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 18:39:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201924#M58559</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-12-30T18:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201925#M58560</link>
      <description>&lt;P&gt;Hi lguinn,&lt;/P&gt;

&lt;P&gt;Hey i tried the approach you suggested. It worked for averages and Medians.&lt;BR /&gt;
But unable to plot the graph using time chart.&lt;/P&gt;

&lt;P&gt;Please find below the query using to draw the time chart&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x host=y source=z | rex "rate-\&amp;gt; (?\d+)" | stats avg(rate) as "Average rate" median(rate) as "Median Rate"  | timechart span=15ms  avg(rate) as "AVG Rate"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm getting this error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'timechart' command: The value for option span (15ms) is invalid. When span is expressed using a sub-second unit (ds, cs, ms, µs), the span value needs to be &amp;lt; 1 second, and 1 second must be evenly divisible by the span value.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2015 18:48:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201925#M58560</guid>
      <dc:creator>nsrao1983</dc:creator>
      <dc:date>2015-12-30T18:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to calculate the average and median for a field in my sample data and produce a time chart?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201926#M58561</link>
      <description>&lt;P&gt;Well, it looks like you could use &lt;CODE&gt;span=10ms&lt;/CODE&gt; or &lt;CODE&gt;span=20ms&lt;/CODE&gt; but not &lt;CODE&gt;span=15ms&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2016 06:43:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-calculate-the-average-and-median-for-a/m-p/201926#M58561</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-01-04T06:43:14Z</dc:date>
    </item>
  </channel>
</rss>

