<?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: help on stats command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465711#M191747</link>
    <description>&lt;P&gt;For a performance boost, you should use &lt;CODE&gt;stats&lt;/CODE&gt; before &lt;CODE&gt;lookup&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2019 15:10:36 GMT</pubDate>
    <dc:creator>skoelpin</dc:creator>
    <dc:date>2019-12-13T15:10:36Z</dc:date>
    <item>
      <title>help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465701#M191737</link>
      <description>&lt;P&gt;hello&lt;/P&gt;

&lt;P&gt;I use the search below in order to count a number of events by SITE&lt;BR /&gt;
If I search a specific site (example | search SITE= TUTU) it works&lt;BR /&gt;
If I search with star (example SITE=T*) it works too but I have to add | stats sum after | stats dc(host) by SITE in order to agregare the count of the different sites&lt;BR /&gt;
My probleme is here because when I am doing stats sum, I lose the field SITE while I need to keep it&lt;BR /&gt;
What I have to do for not having this problem please?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="toto"
| lookup it.csv HOSTNAME as host output SITE 
| search SITE=T* 
| stats dc(host) by SITE 
| fields - SITE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 08:52:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465701#M191737</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-13T08:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465702#M191738</link>
      <description>&lt;P&gt;Hi @jip31,&lt;BR /&gt;
you have to define the exact use case:&lt;BR /&gt;
if you wanto to display the full number of sites, e.g. in a single value panel, you can use something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="toto"
 | lookup it.csv HOSTNAME as host output SITE 
 | search SITE=T* 
 | stats dc(SITE) AS SITE 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If instead you need to display the list of sites and the cont of different hosts for each one you can use the first stats command and add at the end the command addtotals, something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="toto"
| lookup it.csv HOSTNAME as host output SITE 
| search SITE=T* 
| stats dc(host) AS hosts by SITE 
| addtotals labelfield=hosts hosts
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 09:16:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465702#M191738</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-12-13T09:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465703#M191739</link>
      <description>&lt;P&gt;Hi Giuseppe&lt;BR /&gt;
The first solution is not useful because I want to count the host by SITE and not to count the number of SITE...&lt;BR /&gt;
And the second solution is not good, its the same result that in my example&lt;BR /&gt;
I need to keep the field SITE available even if I am doing :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats dc(host) by SITE 
| stats sum
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 09:27:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465703#M191739</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-13T09:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465704#M191740</link>
      <description>&lt;P&gt;Hi @jip31,&lt;BR /&gt;
sorry but I don't understand:&lt;BR /&gt;
you want the list of SITEs and for ech the number of distinct hosts&lt;BR /&gt;
then in the last row, you want the sum of hosts (that comes from the dc option in stats command), what do you want in addition? the number of SITEs?&lt;BR /&gt;
if this is your need, try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="toto"
 | lookup it.csv HOSTNAME as host output SITE 
 | search SITE=T* 
 | stats dc(host) AS hosts by SITE 
 | addtotals labelfield=hosts label="Total" hosts
 | eventstats dc(SITE) AS dcSITE
| eval SITE=if(SITE="Total","Total: ".dcSITE,SITE)
| fields - dcSITE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 10:22:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465704#M191740</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-12-13T10:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465705#M191741</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="toto"
| lookup it.csv HOSTNAME as host output SITE 
| search SITE=T* 
| stats count dc(host) AS hosts BY SITE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then either:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats sum(count) AS TotalCount sum(hosts) AS TotalHosts
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| addtotals row=f col=t
| fillnull value="GrandTotals" SITE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 10:29:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465705#M191741</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-13T10:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465706#M191742</link>
      <description>&lt;P&gt;good thanks&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 12:02:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465706#M191742</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-13T12:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465707#M191743</link>
      <description>&lt;P&gt;last question&lt;BR /&gt;
I want to display only "GrandTotals" in a single panel value &lt;BR /&gt;
what I have to do please??&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 12:37:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465707#M191743</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-13T12:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465708#M191744</link>
      <description>&lt;P&gt;at the end,&lt;BR /&gt;
&lt;CODE&gt;table GrandTotals *&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 13:11:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465708#M191744</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-13T13:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465709#M191745</link>
      <description>&lt;P&gt;Its what I have done but every count for every site are always displayed&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 13:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465709#M191745</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-12-13T13:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465710#M191746</link>
      <description>&lt;P&gt;Ah, I see., then do this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| addtotals row=t col=t fieldname="Grand Total"
| fillnull value="Grand Total"
| tail 1
| table "Grand Total"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 15:02:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465710#M191746</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-13T15:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: help on stats command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465711#M191747</link>
      <description>&lt;P&gt;For a performance boost, you should use &lt;CODE&gt;stats&lt;/CODE&gt; before &lt;CODE&gt;lookup&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 15:10:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-stats-command/m-p/465711#M191747</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2019-12-13T15:10:36Z</dc:date>
    </item>
  </channel>
</rss>

