<?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: eventstats  function issue in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271942#M190156</link>
    <description>&lt;P&gt;Thanks for the mail.&lt;/P&gt;

&lt;P&gt;I am taking &lt;CODE&gt;count(_time)&lt;/CODE&gt; and &lt;CODE&gt;max(_time)&lt;/CODE&gt; and &lt;CODE&gt;computer count&lt;/CODE&gt;. Since I need the timespan, I use &lt;CODE&gt;eventstats&lt;/CODE&gt; function to get it. &lt;BR /&gt;
This is my query: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=tmportal2010prod sourcetype=iis
| eval RPS=strftime(_time,"%Y-%m-%d %H:%M:%S")
| eval RPS_Not401= if(sc_status!="401", RPS,null())
| eventstats count(RPS_Not401) as RPS_Not401_Count by RPS_Not401_Count
| stats avg(RPS_Not401_Count) as "Avg. Requests Per Second" 
           max(RPS_Not401_Count) as "Max Requests Per Second"
           count(s_computername) as "ElementsHits"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My Result set is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;avg(count)       Max(count)     computer_Count
100                     150              62000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without &lt;CODE&gt;eventstats&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=tmportal2010prod sourcetype=iis
| eval RPS=strftime(_time,"%Y-%m-%d %H:%M:%S")
| eval RPS_Not401= if(sc_status!="401", RPS,null())
| stats avg(RPS_Not401_Count) as "Avg. Requests Per Second"
           max(RPS_Not401_Count) as "Max Requests Per Second"
           count(s_computername) as "ElementsHits"

avg(count)     max(count)     computer_count
0                      0             5058164
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I call &lt;CODE&gt;eventstats&lt;/CODE&gt;, my count disappears. &lt;/P&gt;

&lt;P&gt;Please help me here.&lt;/P&gt;</description>
    <pubDate>Mon, 30 May 2016 14:54:20 GMT</pubDate>
    <dc:creator>guruwells</dc:creator>
    <dc:date>2016-05-30T14:54:20Z</dc:date>
    <item>
      <title>eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271936#M190150</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
For retriving data from iis logs, I have used various &lt;CODE&gt;eval statements&lt;/CODE&gt;, &lt;CODE&gt;eventstats&lt;/CODE&gt;, and &lt;CODE&gt;stats&lt;/CODE&gt; functions.&lt;BR /&gt;
When I am using &lt;CODE&gt;eventstats&lt;/CODE&gt; in my query, I am seeing different results than when I have not used eventsttats in query (which gives me proper results).&lt;/P&gt;

&lt;P&gt;This is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=iis
| eval aspx_time_taken=if(cs_uri_stem LIKE "%aspx%" AND sc_status!="401",time_taken,null())
| eval csuri_time_taken=if(lower(cs_uri_stem)="/pages/default.aspx" AND sc_status!="401",time_taken,null())
| eval page_time_taken=if(lower(cs_uri_stem)="/view/pages/default.aspx" AND sc_status!="401",time_taken,null())
| eval time_taken_not401=if(sc_status!="401",time_taken,null())
| eval s_computername_all=if(cs_uri_stem LIKE "%aspx%" ,s_computername,null())
| eval s_computername_4s=if(cs_uri_stem LIKE "%aspx%" AND time_taken &amp;gt; 4000 ,s_computername,null())
|  eval s_computername_25s=if(cs_uri_stem LIKE "%aspx%"  AND time_taken &amp;gt; 2500,s_computername,null())
| eval u_name =replace(cs_username, "0#","")
| eval u_name1= replace(u_name, ".w|","")
|eval u_name2=replace(u_name1,"\|","")
| eval u_name2_503=if(sc_status="503",u_name2,null())
| eval s_computername_503=if(sc_status="503",s_computername,null())
|eval RPS=strftime(_time,"%Y-%m-%d %H:%M:%S")
|eval RPS_Not401= if(sc_status!="401", RPS,null())

    |eventstats count(RPS) as RPS_Count by RPS
    |eventstats count(RPS_Not401) as RPS_Not401_Count by RPS_Not401

| eval hitsfoursecond=if(time_taken &amp;gt; 4000,1,0)
| eval hitstwopointfiveseconds=if(time_taken &amp;gt; 2500,1,0)
| eval u_name2_yhp=if(lower(cs_uri_stem)="/view/pages/default.aspx",u_name2,null())
| eval s_computername_yhp=if(lower(cs_uri_stem)="/view/pages/default.aspx",s_computername,null())
|stats avg(RPS_Count) as "Avg. Requests Per Second"
           max(RPS_Count) as "Max Requests Per Second"
           avg(RPS_Not401_Count) as "Avg. Requests Per Second (excl 401)"
           max(RPS_Not401_Count) as "Max Requests Per Second (excl 401)"
           avg(aspx_time_taken) as "Avg. Response Time .aspx (ms)"
           avg(time_taken_not401) as "Avg. Response Time All (ms)"
           count(eval(csuri_time_taken&amp;gt;4000)) as "PageViewsfoureconds"
           count(eval(csuri_time_taken&amp;gt;2500)) as "PageViews_2point5_seconds"
           avg(page_time_taken) as "Standard Page Avg. Response Time (ms)"
           count(page_time_taken) as "Standard Page Views" avg(csuri_time_taken) as "Page Avg. Response Time (ms)"
           count(csuri_time_taken) as "Pageviews" count(s_computername_all) as "No_of_aspx_Hits"
           count(s_computername_4s) as "No_of_aspx_Hits_4_seconds"
           count(s_computername_25s) as "No_of_aspx_Hits_25_seconds" dc(u_name2_503) AS "Unique User 503"
           count(s_computername_503) as "Total 503 Errors" sum(hitsfoursecond) as "hitsfoursecond"
           sum(hitstwopointfiveseconds) as "hitstwopointfiveseconds" dc(u_name2) AS "Unique Users"
           count(s_computername) as "ElementsHits" dc(u_name2_yhp) as "YHP Unique User"
           count(s_computername_yhp) AS "YHP Elements/Hit"
|eval resultset= (hitsfoursecond/ElementsHits) *100
|eval resultset1=(hitstwopointfiveseconds/ElementsHits)*100
|eval resultset2=(PageViewsfoureconds/Pageviews)*100
|eval resultset3=(PageViews_2point5_seconds/Pageviews)*100
|eval resultset4=(No_of_aspx_Hits_4_seconds/No_of_aspx_Hits)
|eval resultset5=(No_of_aspx_Hits_25_seconds/No_of_aspx_Hits)
|eval resultset6=(PageViewsfoureconds/hitsfoursecond)
|rename resultset as "% Hits &amp;gt; 4 seconds"
                 resultset1 as "% Hits &amp;gt; 2.5 seconds"
                 hitsfoursecond as "# of Hits &amp;gt; 4 seconds"
                 hitstwopointfiveseconds as "# of Hits &amp;gt; 2.5 seconds"
                 resultset2 as "% Page Views &amp;gt; 4 seconds"
                 resultset3 as "% Page Views &amp;gt; 2.5 seconds"
                 PageViews as "Page Views"
                 PageViewsfoureconds as "Page Views &amp;gt; 4 seconds"
                 PageViews_2point5_seconds as "Page Views &amp;gt; 2.5 seconds"
                 No_of_aspx_Hits as "# of .aspx Hits"
                 No_of_aspx_Hits_4_seconds as "# of .aspx Hits &amp;gt; 4 seconds"
                 No_of_aspx_Hits_25_seconds as "# of .aspx Hits &amp;gt; 2.5 seconds"
                 resultset4 as "% .aspx Hits &amp;gt; 4 seconds"
                 resultset5 as "% .aspx Hits &amp;gt; 2.5 seconds"
                 resultset6 as "% Redirect Hits &amp;gt; 4 secs to Overall Hits &amp;gt; 4 secs"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2016 13:44:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271936#M190150</guid>
      <dc:creator>guruwells</dc:creator>
      <dc:date>2016-05-27T13:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271937#M190151</link>
      <description>&lt;P&gt;What are you trying to calculate using eventstats? On lighter note, if you're getting proper result without eventstats, just don't use it &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 14:26:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271937#M190151</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-05-27T14:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271938#M190152</link>
      <description>&lt;P&gt;I will demonstrate your problems by an example.&lt;/P&gt;

&lt;P&gt;Let us imagine that you have these events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;RPS
  a
  b
  b
  c
  c
  c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After your call to &lt;CODE&gt;|eventstats count AS RPS_Count BY RPS&lt;/CODE&gt;, you will have this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;RPS    RPS_count
  a            1
  b            2
  b            2
  c            3
  c            3
  c            3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After your call to &lt;CODE&gt;|stats avg(RPS_Count) as "Avg. Requests Per Second"&lt;/CODE&gt;, you will have this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"Avg. Requests Per Second"
(1+2+2+3+3+3)/6=2.3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Surely you can see that this is utterly nonsensical.&lt;/P&gt;

&lt;P&gt;To top it off, you have not done any math with your timeframe so you cannot &lt;EM&gt;possibly&lt;/EM&gt; be accurate in naming this &lt;EM&gt;Per Second&lt;/EM&gt;!&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 14:57:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271938#M190152</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-27T14:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271939#M190153</link>
      <description>&lt;P&gt;Thanks for the mail. I am not able to merge queries without eventstats. Even I can use multiple stats to get the result set, but problem is if we use multiple stats the result set changing. Because stats will take it from interim table. If I use eventstats, I can able to merge the statement, but result count is different. This is what I am exploring.&lt;/P&gt;

&lt;P&gt;How we get exact result.&lt;/P&gt;

&lt;P&gt;Sorry I typed big message.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 08:55:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271939#M190153</guid>
      <dc:creator>guruwells</dc:creator>
      <dc:date>2016-05-30T08:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271940#M190154</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Your explanation is absolutely right.  But when I using eventstats function in query, the result set is varying.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 08:57:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271940#M190154</guid>
      <dc:creator>guruwells</dc:creator>
      <dc:date>2016-05-30T08:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271941#M190155</link>
      <description>&lt;P&gt;Show me your sample data, then show me a mockup of your desired output with a little bit of plain math (not SPL Splunk commands) and I will try to get you  a full solution.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 13:04:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271941#M190155</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-30T13:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271942#M190156</link>
      <description>&lt;P&gt;Thanks for the mail.&lt;/P&gt;

&lt;P&gt;I am taking &lt;CODE&gt;count(_time)&lt;/CODE&gt; and &lt;CODE&gt;max(_time)&lt;/CODE&gt; and &lt;CODE&gt;computer count&lt;/CODE&gt;. Since I need the timespan, I use &lt;CODE&gt;eventstats&lt;/CODE&gt; function to get it. &lt;BR /&gt;
This is my query: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=tmportal2010prod sourcetype=iis
| eval RPS=strftime(_time,"%Y-%m-%d %H:%M:%S")
| eval RPS_Not401= if(sc_status!="401", RPS,null())
| eventstats count(RPS_Not401) as RPS_Not401_Count by RPS_Not401_Count
| stats avg(RPS_Not401_Count) as "Avg. Requests Per Second" 
           max(RPS_Not401_Count) as "Max Requests Per Second"
           count(s_computername) as "ElementsHits"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My Result set is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;avg(count)       Max(count)     computer_Count
100                     150              62000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without &lt;CODE&gt;eventstats&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=tmportal2010prod sourcetype=iis
| eval RPS=strftime(_time,"%Y-%m-%d %H:%M:%S")
| eval RPS_Not401= if(sc_status!="401", RPS,null())
| stats avg(RPS_Not401_Count) as "Avg. Requests Per Second"
           max(RPS_Not401_Count) as "Max Requests Per Second"
           count(s_computername) as "ElementsHits"

avg(count)     max(count)     computer_count
0                      0             5058164
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I call &lt;CODE&gt;eventstats&lt;/CODE&gt;, my count disappears. &lt;/P&gt;

&lt;P&gt;Please help me here.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 14:54:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271942#M190156</guid>
      <dc:creator>guruwells</dc:creator>
      <dc:date>2016-05-30T14:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271943#M190157</link>
      <description>&lt;P&gt;I will answer your question but I have grave concern that what you are doing is not at all what you are intending to do.  Your field names  have &lt;CODE&gt;count&lt;/CODE&gt; in the names but you are claiming that these are actually &lt;CODE&gt;time&lt;/CODE&gt; values.  I find that very hard to believe so I think you are going to end up with absolute garbage.&lt;/P&gt;

&lt;P&gt;In any case, you should be using &lt;CODE&gt;evenstats&lt;/CODE&gt; to create a NEW field name, not to overwrite an existing one (which is causing your other values to drop to zero).  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | eventstats count(RPS_Not401) AS Some_Other_Count BY RPS_Not401_Count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 May 2016 16:48:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271943#M190157</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-30T16:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271944#M190158</link>
      <description>&lt;P&gt;Thanks for your suggestion. I am getting the proper count of computer_count, but I am getting values of avg(count) and max(count) is 0. At the same time I am looking avg(count) and max(count) as well. I will try the options meantime.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 17:38:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271944#M190158</guid>
      <dc:creator>guruwells</dc:creator>
      <dc:date>2016-05-30T17:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271945#M190159</link>
      <description>&lt;P&gt;You really, &lt;EM&gt;really&lt;/EM&gt;, REALLY, &lt;EM&gt;REALLY&lt;/EM&gt; need to show the &lt;EM&gt;RAW&lt;/EM&gt; events and explain what it is that you are trying to do (include a mockup of the final visualization).  I am reasonably confident that you are &lt;EM&gt;WAY&lt;/EM&gt; off track and should back all the way up to the beginning.&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2016 18:43:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271945#M190159</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-05-30T18:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: eventstats  function issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271946#M190160</link>
      <description>&lt;P&gt;sorry. In simple scenario I will explain what I am doing here.&lt;/P&gt;

&lt;P&gt;Query which I am executing here: example:&lt;BR /&gt;
index=tmportal2010prod sourcetype=iis |eval RPS=strftime(_time,"%Y-%m-%d %H:%M:%S")| stats count by RPS&lt;BR /&gt;
Here I am converting built-in timestamp into my required timestamp and then  taking &lt;STRONG&gt;"_time"&lt;/STRONG&gt; count using stats function.&lt;BR /&gt;
Result will be looks like:&lt;/P&gt;

&lt;P&gt;RPS↕                                                 count↕ &lt;/P&gt;

&lt;P&gt;2016-05-30 22:32:00                     69&lt;BR /&gt;&lt;BR /&gt;
2016-05-30 22:32:01                     81&lt;BR /&gt;&lt;BR /&gt;
2016-05-30 22:32:02                    48&lt;BR /&gt;&lt;BR /&gt;
2016-05-30 22:32:03                     &lt;STRONG&gt;99&lt;/STRONG&gt;  &lt;/P&gt;

&lt;P&gt;Using result what I am trying to say is: "2016-05-30 22:32:00" is repeated 69 times.&lt;BR /&gt;
Now using those counts, I am trying to retrieve average count of &lt;STRONG&gt;_ time&lt;/STRONG&gt; and &lt;STRONG&gt;max (count)&lt;/STRONG&gt; of _time.&lt;/P&gt;

&lt;P&gt;example:&lt;BR /&gt;
69+ 81+48+99/4= 74.24 &lt;BR /&gt;
&lt;STRONG&gt;avg(count)&lt;/STRONG&gt; is 74.24 and &lt;STRONG&gt;"max"&lt;/STRONG&gt; value is number of times repeated one is &lt;STRONG&gt;99&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;If I am executing stats function individually I am getting result without any issue. If I want combine these statements into main query, since I will use multiple &lt;STRONG&gt;stats&lt;/STRONG&gt; the result set will vary ( &lt;STRONG&gt;stats&lt;/STRONG&gt; will work with interim table). &lt;BR /&gt;
That's the reason I have used &lt;STRONG&gt;eventstats&lt;/STRONG&gt; to get the result in main query, but even that result set also giving different result set.&lt;/P&gt;

&lt;P&gt;Is that clear now woodcock or you need more information on this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:49:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eventstats-function-issue/m-p/271946#M190160</guid>
      <dc:creator>guruwells</dc:creator>
      <dc:date>2020-09-29T09:49:50Z</dc:date>
    </item>
  </channel>
</rss>

