<?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: search report query with stats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367355#M108366</link>
    <description>&lt;P&gt;Is there a field that defines the app? Like, if &lt;CODE&gt;appName&lt;/CODE&gt; was a field name, it would make sense to do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats avg(TotalTime) AS AverageTime BY appName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Mar 2018 18:02:22 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2018-03-22T18:02:22Z</dc:date>
    <item>
      <title>search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367351#M108362</link>
      <description>&lt;P&gt;My below query works fine:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="jenkins-cicd-*" source="**/test-metrics-summary.json" | rex max_match=0 field=_raw "(?&amp;lt;lineData&amp;gt;[^\n]+)" | mvexpand lineData | spath input=lineData path=env output=singleEnv | spath input=singleEnv | spath input=lineData | eval status=mvindex(status,1)| eval testRunStartTime=mvindex(testRunStartTime,1)| eval testRunEndTime=mvindex(testRunEndTime,1)| eval testFileName=mvindex(testFileName,1)| eval testCaseName=mvindex(testCaseName,1)| eval testCaseId=mvindex(testCaseId,1)| eval TotalTime = strftime(strptime(testRunEndTime , "%Y-%m-%dT%H:%M:%S.%3N") - strptime(testRunStartTime, "%Y-%m-%dT%H:%M:%S.%3N"),  "%Mm %Ss %2Nms")|
   table  status testRunStartTime testRunEndTime testFileName testCaseName testCaseId TotalTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but if i add stats with avg, i am not getting any values other than avg values in the table&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="jenkins-cicd-*" source="**/ctest-metrics-summary.json" | rex max_match=0 field=_raw "(?&amp;lt;lineData&amp;gt;[^\n]+)" | mvexpand lineData | spath input=lineData path=env output=singleEnv | spath input=singleEnv | spath input=lineData | eval status=mvindex(status,1)| eval testRunStartTime=mvindex(testRunStartTime,1)| eval testRunEndTime=mvindex(testRunEndTime,1)| eval testFileName=mvindex(testFileName,1)| eval testCaseName=mvindex(testCaseName,1)| eval testCaseId=mvindex(testCaseId,1)| eval TotalTime = strftime(strptime(testRunEndTime , "%Y-%m-%dT%H:%M:%S.%3N") - strptime(testRunStartTime, "%Y-%m-%dT%H:%M:%S.%3N"),  "%Mm %Ss %2Nms")| stats avg(TotalTime) by TotalTime |
   table  status testRunStartTime testRunEndTime testFileName testCaseName testCaseId TotalTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am getting all fields empty. I want to display average value as AverageTime after filed TotalTime.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 23:58:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367351#M108362</guid>
      <dc:creator>kasimbekur</dc:creator>
      <dc:date>2018-03-21T23:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367352#M108363</link>
      <description>&lt;P&gt;**but if i add stats with avg, i am not getting any values other than TotalValues in the table which comes wrong values.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 00:20:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367352#M108363</guid>
      <dc:creator>kasimbekur</dc:creator>
      <dc:date>2018-03-22T00:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367353#M108364</link>
      <description>&lt;P&gt;What you are describing is the expected behavior of the command you provided. Let's look at the stats command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats avg(TotalTime) BY TotalTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This doesn't really make sense as a command. Roughly translated to English, it says: "For each value of TotalTime, find all other events with the same value for TotalTime, and take the average of TotalTime." So if you have five events that each contain the &lt;CODE&gt;TotalTime=12&lt;/CODE&gt;, then Splunk will take all five events, sum up &lt;CODE&gt;12+12+12+12+12&lt;/CODE&gt; and divide the total by the number of events (5) and return the average: &lt;CODE&gt;12&lt;/CODE&gt;. And so on for every value of TotalTime that Splunk finds. So the command &lt;CODE&gt;| stats avg(TotalTime) BY TotalTime&lt;/CODE&gt; will always yield two columns: &lt;CODE&gt;avg(TotalTime)&lt;/CODE&gt; and &lt;CODE&gt;TotalTime&lt;/CODE&gt;, and they will always have the same value. Follow that up with a &lt;CODE&gt;table&lt;/CODE&gt; command that includes TotalTime but doesn't include &lt;CODE&gt;avg(TotalTime)&lt;/CODE&gt;, and you'll only have values for TotalTime.&lt;/P&gt;

&lt;P&gt;That brings us to the second part of the issue at hand with the &lt;CODE&gt;stats&lt;/CODE&gt; call: if you don't specify a field in the stats call, it won't pass through that part of the query. So no matter how many fields you had before you called &lt;CODE&gt;| stats avg(TotalTime) by TotalTime&lt;/CODE&gt;, you will only be left with two fields afterwards: &lt;CODE&gt;TotalTime&lt;/CODE&gt; and &lt;CODE&gt;avg(TotalTime)&lt;/CODE&gt;. If you remove the table command from the end of your search, you'll see that.&lt;/P&gt;

&lt;P&gt;I'm not sure what quite what your intent is with the stats call, but I &lt;EM&gt;think&lt;/EM&gt; you want the average of all &lt;CODE&gt;TotalTime&lt;/CODE&gt; values as a column. If so, this might get you there:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="jenkins-cicd-*" source="**/ctest-metrics-summary.json" 
| rex max_match=0 field=_raw "(?&amp;lt;lineData&amp;gt;[^\n]+)" 
| mvexpand lineData 
| spath input=lineData path=env output=singleEnv 
| spath input=singleEnv 
| spath input=lineData 
| eval status=mvindex(status,1)
| eval testRunStartTime=mvindex(testRunStartTime,1)
| eval testRunEndTime=mvindex(testRunEndTime,1)
| eval testFileName=mvindex(testFileName,1)
| eval testCaseName=mvindex(testCaseName,1)
| eval testCaseId=mvindex(testCaseId,1)
| eval TotalTime = strftime(strptime(testRunEndTime , "%Y-%m-%dT%H:%M:%S.%3N") - strptime(testRunStartTime, "%Y-%m-%dT%H:%M:%S.%3N"),  "%Mm %Ss %2Nms")
| eventstats avg(TotalTime) AS AverageTime
| table  status testRunStartTime testRunEndTime testFileName testCaseName testCaseId TotalTime AverageTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 00:57:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367353#M108364</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-22T00:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367354#M108365</link>
      <description>&lt;P&gt;I am new to Splunk reporting. &lt;BR /&gt;
I am looking for average time taken for a single app( say myapp) to run its test cases.&lt;BR /&gt;
I run your query, AverageTime gives empty value.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 17:32:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367354#M108365</guid>
      <dc:creator>kasimbekur</dc:creator>
      <dc:date>2018-03-22T17:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367355#M108366</link>
      <description>&lt;P&gt;Is there a field that defines the app? Like, if &lt;CODE&gt;appName&lt;/CODE&gt; was a field name, it would make sense to do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats avg(TotalTime) AS AverageTime BY appName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 18:02:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367355#M108366</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-22T18:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367356#M108367</link>
      <description>&lt;P&gt;I have given &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats avg(TotalTime) AS AverageTime BY testFileName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;still it gives empty&lt;BR /&gt;
Is this issue because of TotalTime is in time format?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 18:59:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367356#M108367</guid>
      <dc:creator>kasimbekur</dc:creator>
      <dc:date>2018-03-22T18:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367357#M108368</link>
      <description>&lt;P&gt;Oh, yes. It sure would. Can you copy/paste in the current results - or at least a few rows? I'll help you get that parsed out and fixed.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 20:00:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367357#M108368</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-22T20:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367358#M108369</link>
      <description>&lt;P&gt;i have updated above main comment section. I want to find average time to run each application. I hope this can be done by subtracting testRunEndTime - testRunStartTime. Also will be better if I get average of each test cases in an application. i.e. testCaseEndTime - testCaseStartTime&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 20:25:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367358#M108369</guid>
      <dc:creator>kasimbekur</dc:creator>
      <dc:date>2018-03-22T20:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367359#M108370</link>
      <description>&lt;P&gt;Ok, I think I'm getting your goal now. How about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="jenkins-cicd-*" source="**/ctest-metrics-summary.json" 
 | rex max_match=0 field=_raw "(?[^\n]+)" 
 | mvexpand lineData 
 | spath input=lineData path=env output=singleEnv 
 | spath input=singleEnv 
 | spath input=lineData 
 | eval status=mvindex(status,1)
 | eval testRunStartTime=mvindex(testRunStartTime,1)
 | eval testRunEndTime=mvindex(testRunEndTime,1)
 | eval testFileName=mvindex(testFileName,1)
 | eval testCaseName=mvindex(testCaseName,1)
 | eval testCaseId=mvindex(testCaseId,1)
 | eval TotalTime = strptime(testRunEndTime , "%Y-%m-%dT%H:%M:%S.%3N") - strptime(testRunStartTime, "%Y-%m-%dT%H:%M:%S.%3N")
 | eventstats avg(TotalTime) AS AverageTime BY testCaseName
 | fieldformat TotalTime=strftime(TotalTime, "%Mm %Ss %2Nms")
 | table  status testRunStartTime testRunEndTime testFileName testCaseName testCaseId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;TotalTime AverageTime&lt;BR /&gt;
If you'd rather do it by &lt;CODE&gt;testCaseEndTime&lt;/CODE&gt; instead of &lt;CODE&gt;testRunEndTime&lt;/CODE&gt; (and likewise for the start times), just substitute the field names in place. The major change I made here is to not use the &lt;CODE&gt;eval&lt;/CODE&gt; command to change the actual value of the field TotalTime but instead use &lt;CODE&gt;fieldformat&lt;/CODE&gt;, which changes the way the value is presented but not the way it's used in calculations. I also moved this to after the calculation of the AverageTime, so it actually could be either an eval or a fieldformat - as long as the value of TotalTime is a number at the time when we calculate the average.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 00:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367359#M108370</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-23T00:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367360#M108371</link>
      <description>&lt;P&gt;fantastic, it worked. +1 for your detailed explanation of each steps and functions used, this really helped to understand the Splunk report concept than just fixing issues.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 17:58:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367360#M108371</guid>
      <dc:creator>kasimbekur</dc:creator>
      <dc:date>2018-03-23T17:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: search report query with stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367361#M108372</link>
      <description>&lt;P&gt;Awesome. Glad I could help you understand! That's always my goal. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 18:27:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-report-query-with-stats/m-p/367361#M108372</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-23T18:27:07Z</dc:date>
    </item>
  </channel>
</rss>

