<?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 edit and optimize my search to calculate the average and format top ten results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166067#M47276</link>
    <description>&lt;P&gt;It would work  with some fiddling - max and min are very close , so max-min=0 However, it gives leads where to check&lt;/P&gt;

&lt;P&gt;I have already re-done the search using the old ideas, but will use the version above as a know how for future cases:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" "url" evttype=INFO | bucket _time span=24h | stats dc(clientip) as uniq, count as total by _time | timechart span=24h per_day(total) as TotalHits, per_day(uniq) as UniqueHits, per_hour(total) as PerHour per_minute(total) as PerMinute | appendcols [search source="mysource" "url" evvtype=INFO | bucket _time span=24h | top clientip limit="N" by _time| sort -count| eval pair=clientip." (".count.")" | stats values(pair) as TOP"N"_IP by _time]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It still needs some small fixes but looks a bit neater than the previous and the per_hour/minute is calculated automatically.&lt;BR /&gt;
Same trouble with span&amp;lt;24h, but I will check that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Oct 2014 20:50:53 GMT</pubDate>
    <dc:creator>atanasmitev</dc:creator>
    <dc:date>2014-10-17T20:50:53Z</dc:date>
    <item>
      <title>How to edit and optimize my search to calculate the average and format top ten results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166065#M47274</link>
      <description>&lt;P&gt;I have a working search that calculates total hits, avg(per_hour), avg(per_minute), top10 IPs with count and value. Now I have a couple of problems that need optimization/or fixing : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  source="mysource" "POST url" evttype=INFO | bucket _time span=24h | stats dc(clientIP) as Unique_IP_Hits, count as Total_Hits by _time  |  eval avg_perhour=(Total_Hits/24) | eval avg_perminute=(avg_perhour/60) | table _time, Total_Hits, Unique_IP_Hits, avg_perhour, avg_perminute| appendcols [searchsource="mysource" "POST url" evttype=INFO | bucket _time span=24h | top clientIP limit=5 by _time| sort -count| eval pair=clientIP." (".count.")" | stats values(pair) as TOP10_IP]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time     Total_Hits         Unique_IP_Hits      perhour       perminute   Top10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now here are my concerns where I need help:&lt;BR /&gt;
1) The avg(per_time) is calculated statically , i.e (total/24), so if the span is less than 24 it wont work. There is a | timechart span=X h per_hour(total) command that I can't get to work with this search&lt;BR /&gt;
2) The top10 spans the upper right cell, I need to either merge all rightmost cells, or find a solution to get (top10 per day)&lt;BR /&gt;
3) Optional - if we get to work the 1) and 2), is there a more short/nice way of rewriting the search.&lt;/P&gt;

&lt;P&gt;I know it's a lot of work and I don't expect prompt response, but will be glad if you could.&lt;/P&gt;

&lt;P&gt;Thanks in advance, &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:54:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166065#M47274</guid>
      <dc:creator>atanasmitev</dc:creator>
      <dc:date>2020-09-28T17:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit and optimize my search to calculate the average and format top ten results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166066#M47275</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; source="mysource" "POST url" evttype=INFO 
 | eventstats max(_time) as max min(_time) as min by _time | eval durationSec=max-min
 | bucket _time span=1d | stats count , first(durationSec) as durationSec by _time, clientIP 
 | eventstats sum(count) as Total_Hits count as Unique_IP_Hits by _time
 | eval pair=clientIP." (".count.")"
 | sort 0 _time - count    | streamstats count as sno by _time     | where sno&amp;lt;6
 | stats first(Total_Hits) as Total_Hists, first(Unique_IP_Hits) as Unique_IP_Hits
 values(pair) as TOP10_IP first(durationSec) as durationSec by _time
 | eval avg_perhour=(Total_Hits/(floor(durationSec/3600))) 
 | eval avg_perminute=(Total_Hits/(floor(durationSec/3600*60))) 
 | table _time, Total_Hits, Unique_IP_Hits, avg_perhour, avg_perminute,TOP10_IP
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Oct 2014 19:26:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166066#M47275</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-10-17T19:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit and optimize my search to calculate the average and format top ten results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166067#M47276</link>
      <description>&lt;P&gt;It would work  with some fiddling - max and min are very close , so max-min=0 However, it gives leads where to check&lt;/P&gt;

&lt;P&gt;I have already re-done the search using the old ideas, but will use the version above as a know how for future cases:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="mysource" "url" evttype=INFO | bucket _time span=24h | stats dc(clientip) as uniq, count as total by _time | timechart span=24h per_day(total) as TotalHits, per_day(uniq) as UniqueHits, per_hour(total) as PerHour per_minute(total) as PerMinute | appendcols [search source="mysource" "url" evvtype=INFO | bucket _time span=24h | top clientip limit="N" by _time| sort -count| eval pair=clientip." (".count.")" | stats values(pair) as TOP"N"_IP by _time]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It still needs some small fixes but looks a bit neater than the previous and the per_hour/minute is calculated automatically.&lt;BR /&gt;
Same trouble with span&amp;lt;24h, but I will check that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2014 20:50:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-and-optimize-my-search-to-calculate-the-average-and/m-p/166067#M47276</guid>
      <dc:creator>atanasmitev</dc:creator>
      <dc:date>2014-10-17T20:50:53Z</dc:date>
    </item>
  </channel>
</rss>

