<?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: Can you help us with a basic search that uses the stats command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422014#M121189</link>
    <description>&lt;P&gt;Note that this way you have no way of telling which count belongs to which source, as values() does a lexicographical sort.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2019 12:28:15 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2019-03-06T12:28:15Z</dc:date>
    <item>
      <title>Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422006#M121181</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;With the code below, I count the event number by source for a sourcetype.&lt;/P&gt;

&lt;P&gt;But different sources use the same sourcetype.&lt;/P&gt;

&lt;P&gt;So I have the sourcetype field reproduced many times.&lt;/P&gt;

&lt;P&gt;I just want to count the events number by source for only one sourcetype.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x| stats count by sourcetype, source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried this but it doesn't do what I want&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="x" sourcetype=* host=* 
| stats values(source) by sourcetype| stats count by sourcetype, source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;could you help me please?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 11:13:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422006#M121181</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-03-05T11:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422007#M121182</link>
      <description>&lt;P&gt;@jip31 &lt;/P&gt;

&lt;P&gt;Are you looking for these?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| chart count over sourcetype by source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| chart count over source by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2019 11:27:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422007#M121182</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-03-05T11:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422008#M121183</link>
      <description>&lt;P&gt;Could you provide an example, screenshot or some events and try to describe the desired outcome with their values?&lt;BR /&gt;
For me your SPL is answering your question already.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 11:45:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422008#M121183</guid>
      <dc:creator>damann</dc:creator>
      <dc:date>2019-03-05T11:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422009#M121184</link>
      <description>&lt;P&gt;not exactly&lt;BR /&gt;
I need to have a table with a column with the sourcetype name, a column linked to the first column in order to have all the sources for a specific sourcetype and a last column with the count of events by source....&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 13:32:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422009#M121184</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-03-05T13:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422010#M121185</link>
      <description>&lt;P&gt;@jip31 ,&lt;/P&gt;

&lt;P&gt;If you want to group all sources by sourcetype, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="your index"
| stats count by sourcetype,source
| stats values(source) as source,values(count) as count by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt; &lt;BR /&gt;
In the above result, source and count might not have a 1-1 mapping since the &lt;CODE&gt;values&lt;/CODE&gt; will sort them lexicographically .&lt;BR /&gt;
Try instead&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | stats count by source,sourcetype
    | eval combined=source." | ".count
    | stats values(combined) as source by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2019 14:01:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422010#M121185</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-03-05T14:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422011#M121186</link>
      <description>&lt;P&gt;index=yourindex sourcetype="sourcetype you are looking for " | stats count by  source&lt;/P&gt;

&lt;P&gt;another way &lt;/P&gt;

&lt;P&gt;index=yourindex | stats count by  source | search sourcetype="sourcetype you are looking for " &lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 15:48:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422011#M121186</guid>
      <dc:creator>tsaikumar009</dc:creator>
      <dc:date>2019-03-05T15:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422012#M121187</link>
      <description>&lt;P&gt;&lt;EM&gt;"I need to have a table with a column with the sourcetype name, a column linked to the first column in order to have all the sources for a specific sourcetype and a last column with the count of events by source...."&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Your original attempt was close, but you need to combine both into 1 stats command, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="x"
| stats count values(source) by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Edit: Just realized I read your requirement wrong. You need the count by source, not by sourcetype, so above would not really work. But your requirements are then conflicting. You want the count by sourcetype,source, but for some reason have a problem with repeating the sourcetype value for each related source.&lt;/P&gt;

&lt;P&gt;This should do the trick:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | stats count by source,sourcetype
 | stats list(source) as source list(count) as count by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2019 15:57:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422012#M121187</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-03-05T15:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422013#M121188</link>
      <description>&lt;P&gt;perfect renjith many thanks&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 10:23:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422013#M121188</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-03-06T10:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422014#M121189</link>
      <description>&lt;P&gt;Note that this way you have no way of telling which count belongs to which source, as values() does a lexicographical sort.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 12:28:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422014#M121189</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-03-06T12:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422015#M121190</link>
      <description>&lt;P&gt;@jip31 , What @FrankVl  mentioned is absolutely right. You might not have a 1-1 mapping between source &amp;amp; count. If you need this try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by source,sourcetype
| eval combined=source." | ".count
| stats values(combined) as source by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I will update the answer and would "unaccept" it. &lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 13:06:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422015#M121190</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-03-06T13:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help us with a basic search that uses the stats command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422016#M121191</link>
      <description>&lt;P&gt;Basically his requirements are conflicting. He wants count by sourcetype,source, but without repeating the sourcetype value each time.&lt;/P&gt;

&lt;P&gt;Now, you can of course pull tricks like combining source and count in 1 field. Or something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by source,sourcetype
| stats list(source) as source list(count) as count by sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(list keeps the original order)&lt;/P&gt;

&lt;P&gt;But I'm quite curious why a simple &lt;CODE&gt;| stats count by source,sourcetype&lt;/CODE&gt; wouldn't be OK.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 13:25:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-us-with-a-basic-search-that-uses-the-stats-command/m-p/422016#M121191</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-03-06T13:25:53Z</dc:date>
    </item>
  </channel>
</rss>

