<?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: How to Optimize Splunk Query to Avoid Join and Retain All Metrics with xyseries? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/How-to-Optimize-Splunk-Query-to-Avoid-Join-and-Retain-All/m-p/702394#M10318</link>
    <description>&lt;P&gt;Glad you saw sense and ditched chatGPT!&lt;/P&gt;&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=sample_index sourcetype=kube:container:sample_container
| fields U, S, D
| where isnotnull(U) and isnotnull(S) and isnotnull(D)
| rex field=U "(?P&amp;lt;ApiName&amp;gt;[^/]+)(?=\/[0-9a-fA-F\-]+$|$)"
| eventstats min(D) as Min, max(D) as Max, avg(D) as Avg, perc95(D) as P95, perc98(D) as P98, perc99(D) as P99 by ApiName
| stats count as TotalReq, by ApiName, Min, Max, Avg, P95, P98, P99, S
| eval {S}=TotalReq
| stats values(1*) as 1* values(2*) as 2* values(3*) as 3* values(4*) as 4* values(5*) as 5* sum(TotalReq) as TotalReq by ApiName, Min, Max, Avg, P95, P98, P99
| addtotals labelfield=ApiName col=t label="ColumnTotals" 1* 2* 3* 4* 5* TotalReq
| addinfo
| eval Availability% = round(100 - ('500'*100/TotalReq),8)
| fillnull value=100 Availability%
| eval range = info_max_time - info_min_time
| eval AvgTPS=round(TotalReq/range,5) | eval Avg=floor(Avg) | eval P95=floor(P95) | eval P98=floor(P98) | eval P99=floor(P99)
| sort TotalReq
| table ApiName, 1*, 2*, 3*, 4*, 5*, Min, Max, Avg, P95, P98, P99, AvgTPS, Availability%, TotalReq&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 21 Oct 2024 15:40:41 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2024-10-21T15:40:41Z</dc:date>
    <item>
      <title>How to Optimize Splunk Query to Avoid Join and Retain All Metrics with xyseries?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-Optimize-Splunk-Query-to-Avoid-Join-and-Retain-All/m-p/702379#M10317</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;I'm working on a Splunk query to analyze API request metrics, and I want to avoid using a join as it is making my query slow. The main challenge is that I need to aggregate multiple metrics (like&amp;nbsp;min,&amp;nbsp;max,&amp;nbsp;avg, and percentiles) and pivot HTTP status codes (S) into columns, but the current approach withxyseries&amp;nbsp;is dropping additional values:&amp;nbsp;Min, Max, Avg, P95, P98, P99&lt;/P&gt;
&lt;P&gt;The reason why using&amp;nbsp;xyseries - it generates columns dynamically so that my result will contain only available statuses from many available and it count accordingly .&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here’s the original working query with join:&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=sample_index sourcetype=kube:container:sample_container
| fields U, S, D
| where isnotnull(U) and isnotnull(S) and isnotnull(D)
| rex field=U "(?P&amp;lt;ApiName&amp;gt;[^/]+)(?=\/[0-9a-fA-F\-]+$|$)"
| stats count as TotalReq, by ApiName, S
| xyseries ApiName S, TotalReq
| addtotals labelfield=ApiName col=t label="ColumnTotals" fieldname="TotalReq"
| join type=left ApiName
[ search index=sample_index sourcetype=kube:container:sample_container
| fields U, S, D
| where isnotnull(U) and isnotnull(S) and isnotnull(D)
| rex field=U "(?P&amp;lt;ApiName&amp;gt;[^/]+)(?=\/[0-9a-fA-F\-]+$|$)"
| stats min(D) as Min, max(D) as Max, avg(D) as Avg, perc95(D) as P95, perc98(D) as P98, perc99(D) as P99 by ApiName]
| addinfo
| eval Availability% = round(100 - ('500'*100/TotalReq), ‌&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;‌
| fillnull value=100 Availability%
| eval range = info_max_time - info_min_time
| eval AvgTPS=round(TotalReq/range,5) | eval Avg=floor(Avg) | eval P95=floor(P95) | eval P98=floor(P98) | eval P99=floor(P99)
| sort TotalReq
| table ApiName, 1*, 2*, 3*, 4*, 5*, Min, Max, Avg, P95, P98, P99, AvgTPS, Availability%, TotalReq&lt;/LI-CODE&gt;
&lt;P&gt;I attempted to optimize it by combining the metrics calculation into a single stats command and usingeventstats&amp;nbsp;or&amp;nbsp;streamstats&amp;nbsp;to calculate the additional statistics without dropping the required fields.&amp;nbsp; Also providing additional metrics with&amp;nbsp;xyseries as below but did not help.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PS: Tried with chatGPT did not help. so seeking help from real experts &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| stats count as TotalReq, min(D) as Min, max(D) as Max, avg(D) as Avg, perc95(D) as P95, perc98(D) as P98, perc99(D) as P99 by ApiName, S
| xyseries ApiName S, TotalReq, Min, Max, Avg, P95, P98, P99&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 21 Oct 2024 21:51:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-Optimize-Splunk-Query-to-Avoid-Join-and-Retain-All/m-p/702379#M10317</guid>
      <dc:creator>ravimishrabglr</dc:creator>
      <dc:date>2024-10-21T21:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Optimize Splunk Query to Avoid Join and Retain All Metrics with xyseries?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-Optimize-Splunk-Query-to-Avoid-Join-and-Retain-All/m-p/702394#M10318</link>
      <description>&lt;P&gt;Glad you saw sense and ditched chatGPT!&lt;/P&gt;&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=sample_index sourcetype=kube:container:sample_container
| fields U, S, D
| where isnotnull(U) and isnotnull(S) and isnotnull(D)
| rex field=U "(?P&amp;lt;ApiName&amp;gt;[^/]+)(?=\/[0-9a-fA-F\-]+$|$)"
| eventstats min(D) as Min, max(D) as Max, avg(D) as Avg, perc95(D) as P95, perc98(D) as P98, perc99(D) as P99 by ApiName
| stats count as TotalReq, by ApiName, Min, Max, Avg, P95, P98, P99, S
| eval {S}=TotalReq
| stats values(1*) as 1* values(2*) as 2* values(3*) as 3* values(4*) as 4* values(5*) as 5* sum(TotalReq) as TotalReq by ApiName, Min, Max, Avg, P95, P98, P99
| addtotals labelfield=ApiName col=t label="ColumnTotals" 1* 2* 3* 4* 5* TotalReq
| addinfo
| eval Availability% = round(100 - ('500'*100/TotalReq),8)
| fillnull value=100 Availability%
| eval range = info_max_time - info_min_time
| eval AvgTPS=round(TotalReq/range,5) | eval Avg=floor(Avg) | eval P95=floor(P95) | eval P98=floor(P98) | eval P99=floor(P99)
| sort TotalReq
| table ApiName, 1*, 2*, 3*, 4*, 5*, Min, Max, Avg, P95, P98, P99, AvgTPS, Availability%, TotalReq&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 21 Oct 2024 15:40:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-Optimize-Splunk-Query-to-Avoid-Join-and-Retain-All/m-p/702394#M10318</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-10-21T15:40:41Z</dc:date>
    </item>
  </channel>
</rss>

