<?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: Summary index queries in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315903#M5160</link>
    <description>&lt;P&gt;Your problem has nothing to do with summary indexes, just understanding how to use &lt;CODE&gt;stats&lt;/CODE&gt;.  Any of the following could have used &lt;CODE&gt;timechart&lt;/CODE&gt; for part of the solution -- &lt;CODE&gt;timechart&lt;/CODE&gt; can implicitly do the &lt;CODE&gt;bin&lt;/CODE&gt; and the &lt;CODE&gt;per_second&lt;/CODE&gt; calculation for you, but it also has a couple of finnicky things about it, and I figure you need your answer more than you need to practice &lt;CODE&gt;timechart&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Use this if you want to know the max actual calls in a real second, assuming there is an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields count, _time, pot_type
| rename count as Count
| bin _time span=1s
| stats sum(Count) as Calls_Per_Second by pot_type _time
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use this if you want to know the max actual calls in a real second, assuming there is NOT an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields _time, pot_type
| bin _time span=1s
| stats count as Calls_Per_Second by pot_type _time
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use this if you want to know the Peak number of calls in any 5 minute period, and want that peak expressed in terms of calls per second, assuming there is an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields count, _time, pot_type
| rename count as Count
| bin _time span=5m
| stats sum(Count) as Calls_Per_Second by pot_type _time
| eval Calls_Per_Second = round(Calls_Per_Second/300,0)
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use this if you want to know the Peak number of calls in any 5 minute period, and want that peak expressed in terms of calls per second, assuming there is NOT an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields _time, pot_type
| bin _time span=5m
| stats count as Calls_Per_Second by pot_type _time
| eval Calls_Per_Second = round(Calls_Per_Second/300,0)
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Just for comparison, a &lt;CODE&gt;timechart&lt;/CODE&gt; version...&lt;/P&gt;

&lt;P&gt;Use this if you want to know the max actual calls in a real second, assuming there is an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| table count, _time, pot_type
| rename count as Count
| timechart span=1s per_second(Count) as Calls_Per_Second by pot_type
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If there is no such field as &lt;CODE&gt;count&lt;/CODE&gt; , change the &lt;CODE&gt;rename&lt;/CODE&gt; command to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Count = 1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want the average &lt;CODE&gt;per_second&lt;/CODE&gt; value across 5 minutes, change the &lt;CODE&gt;timechart&lt;/CODE&gt; &lt;CODE&gt;span&lt;/CODE&gt; value to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=5m per_second(Count) as Calls_Per_Second by pot_type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Oh, by the way, every one of those versions gets rid of the &lt;CODE&gt;_time&lt;/CODE&gt;, so you don't know when that max value actually happened.  If you want to retain the &lt;CODE&gt;_time&lt;/CODE&gt;, change the last line to these three ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats max(Calls_Per_Second) as MaxCalls by pot_type 
| where Calls_Per_Second = MaxCalls 
| sort 0 pot_type _time 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Jul 2017 00:13:32 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-07-19T00:13:32Z</dc:date>
    <item>
      <title>Summary index queries</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315901#M5158</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am using Splunk for a web application that sells pots. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;WHAT I HAVE&lt;/STRONG&gt;: Query for maximum no of calls for each pot type,&lt;/P&gt;

&lt;P&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf &lt;STRONG&gt;&lt;EM&gt;pot_type="wood"&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;
| fields count,_time&lt;BR /&gt;
| timechart per_second(count) as Calls_Per_Second &lt;BR /&gt;
| eval Calls_Per_Second=max(Calls_Per_Second) &lt;BR /&gt;
| fields Calls_Per_Second &lt;BR /&gt;
| stats max(Calls_Per_Second)&lt;/P&gt;

&lt;P&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf &lt;STRONG&gt;&lt;EM&gt;pot_type="clay"&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;
| fields count,_time&lt;BR /&gt;
| timechart per_second(count) as Calls_Per_Second &lt;BR /&gt;
| eval Calls_Per_Second=max(Calls_Per_Second) &lt;BR /&gt;
| fields Calls_Per_Second &lt;BR /&gt;
| stats max(Calls_Per_Second)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;WHAT I NEED&lt;/STRONG&gt;: Use a summary index for the above queries.&lt;BR /&gt;
I have created the below query for summary index,&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;THIS QUERY WORKS:&lt;/STRONG&gt;&lt;BR /&gt;
(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf&lt;BR /&gt;
| eval count=1 &lt;BR /&gt;
| timechart per_second(count) as Calls_Per_Second by pot_type &lt;BR /&gt;
| table * &lt;BR /&gt;
| fields - _time&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;THIS QUERY DOESN'T:&lt;/STRONG&gt;&lt;BR /&gt;
(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf&lt;BR /&gt;
| eval count=1 &lt;BR /&gt;
| timechart per_second(count) as Calls_Per_Second by pot_type &lt;BR /&gt;
| table * &lt;BR /&gt;
| fields - _time &lt;BR /&gt;
| search pot_type=wood &lt;BR /&gt;
| eval Calls_Per_Second=max(Calls_Per_Second) &lt;BR /&gt;
| fields Calls_Per_Second &lt;BR /&gt;
| stats max(Calls_Per_Second)&lt;/P&gt;

&lt;P&gt;Please help.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Deepak&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:56:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315901#M5158</guid>
      <dc:creator>deepak02</dc:creator>
      <dc:date>2020-09-29T14:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Summary index queries</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315902#M5159</link>
      <description>&lt;P&gt;You seem to be confused about summary indexes.  To use a summary index, a scheduled search will write summary results to an index ("sales_summary") using the &lt;CODE&gt;collect&lt;/CODE&gt; command.  A separate search then reads from that summary index using &lt;CODE&gt;index=sales_summary&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;What exactly are trying to accomplish?  Perhaps we can suggest another way to get there.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:56:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315902#M5159</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-09-29T14:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summary index queries</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315903#M5160</link>
      <description>&lt;P&gt;Your problem has nothing to do with summary indexes, just understanding how to use &lt;CODE&gt;stats&lt;/CODE&gt;.  Any of the following could have used &lt;CODE&gt;timechart&lt;/CODE&gt; for part of the solution -- &lt;CODE&gt;timechart&lt;/CODE&gt; can implicitly do the &lt;CODE&gt;bin&lt;/CODE&gt; and the &lt;CODE&gt;per_second&lt;/CODE&gt; calculation for you, but it also has a couple of finnicky things about it, and I figure you need your answer more than you need to practice &lt;CODE&gt;timechart&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Use this if you want to know the max actual calls in a real second, assuming there is an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields count, _time, pot_type
| rename count as Count
| bin _time span=1s
| stats sum(Count) as Calls_Per_Second by pot_type _time
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use this if you want to know the max actual calls in a real second, assuming there is NOT an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields _time, pot_type
| bin _time span=1s
| stats count as Calls_Per_Second by pot_type _time
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use this if you want to know the Peak number of calls in any 5 minute period, and want that peak expressed in terms of calls per second, assuming there is an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields count, _time, pot_type
| rename count as Count
| bin _time span=5m
| stats sum(Count) as Calls_Per_Second by pot_type _time
| eval Calls_Per_Second = round(Calls_Per_Second/300,0)
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use this if you want to know the Peak number of calls in any 5 minute period, and want that peak expressed in terms of calls per second, assuming there is NOT an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| fields _time, pot_type
| bin _time span=5m
| stats count as Calls_Per_Second by pot_type _time
| eval Calls_Per_Second = round(Calls_Per_Second/300,0)
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Just for comparison, a &lt;CODE&gt;timechart&lt;/CODE&gt; version...&lt;/P&gt;

&lt;P&gt;Use this if you want to know the max actual calls in a real second, assuming there is an actual field called &lt;CODE&gt;count&lt;/CODE&gt; on the record.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index="sales_data") app="Pottery" sourcetype=app_Pottery_Perf pot_type=*
| table count, _time, pot_type
| rename count as Count
| timechart span=1s per_second(Count) as Calls_Per_Second by pot_type
| stats max(Calls_Per_Second) as MaxCalls by pot_type 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If there is no such field as &lt;CODE&gt;count&lt;/CODE&gt; , change the &lt;CODE&gt;rename&lt;/CODE&gt; command to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Count = 1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want the average &lt;CODE&gt;per_second&lt;/CODE&gt; value across 5 minutes, change the &lt;CODE&gt;timechart&lt;/CODE&gt; &lt;CODE&gt;span&lt;/CODE&gt; value to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=5m per_second(Count) as Calls_Per_Second by pot_type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Oh, by the way, every one of those versions gets rid of the &lt;CODE&gt;_time&lt;/CODE&gt;, so you don't know when that max value actually happened.  If you want to retain the &lt;CODE&gt;_time&lt;/CODE&gt;, change the last line to these three ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats max(Calls_Per_Second) as MaxCalls by pot_type 
| where Calls_Per_Second = MaxCalls 
| sort 0 pot_type _time 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jul 2017 00:13:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Summary-index-queries/m-p/315903#M5160</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-19T00:13:32Z</dc:date>
    </item>
  </channel>
</rss>

