<?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 Calculate error percentage of HTTPStatus in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660266#M227916</link>
    <description>&lt;P&gt;index=sample(Consumer="prod") ServiceName="product.services.prd.*"&lt;BR /&gt;| stats count(eval(HTTPStatus &amp;gt;= 400 AND HTTPStatus &amp;lt; 500)) AS 'fourxxErrors', count(eval(HTTPStatus &amp;gt;= 500 AND HTTPStatus &amp;lt; 600)) AS 'fivexxErrors', count AS 'TotalRequests'&lt;BR /&gt;| eval 'fourxxPercentage' = if('TotalRequests' &amp;gt; 0, ('fourxxErrors' / 'TotalRequests') * 100, 0), 'fivexxPercentage' = if('TotalRequests' &amp;gt; 0, ('fivexxErrors' / 'TotalRequests') * 100, 0)&lt;BR /&gt;| table "fourxxPercentage", "fivexxPercentage"&lt;BR /&gt;&lt;BR /&gt;The result is showing as 0 for both fields inside the table "fourxxPercentage", "fivexxPercentage". Actually,&amp;nbsp;fourxxErrors and&amp;nbsp;fivexxErrors count are greater than 0. Is that because it's not showing the decimal values?&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 17:59:21 GMT</pubDate>
    <dc:creator>kris1733</dc:creator>
    <dc:date>2023-10-10T17:59:21Z</dc:date>
    <item>
      <title>Calculate error percentage of HTTPStatus</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660266#M227916</link>
      <description>&lt;P&gt;index=sample(Consumer="prod") ServiceName="product.services.prd.*"&lt;BR /&gt;| stats count(eval(HTTPStatus &amp;gt;= 400 AND HTTPStatus &amp;lt; 500)) AS 'fourxxErrors', count(eval(HTTPStatus &amp;gt;= 500 AND HTTPStatus &amp;lt; 600)) AS 'fivexxErrors', count AS 'TotalRequests'&lt;BR /&gt;| eval 'fourxxPercentage' = if('TotalRequests' &amp;gt; 0, ('fourxxErrors' / 'TotalRequests') * 100, 0), 'fivexxPercentage' = if('TotalRequests' &amp;gt; 0, ('fivexxErrors' / 'TotalRequests') * 100, 0)&lt;BR /&gt;| table "fourxxPercentage", "fivexxPercentage"&lt;BR /&gt;&lt;BR /&gt;The result is showing as 0 for both fields inside the table "fourxxPercentage", "fivexxPercentage". Actually,&amp;nbsp;fourxxErrors and&amp;nbsp;fivexxErrors count are greater than 0. Is that because it's not showing the decimal values?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 17:59:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660266#M227916</guid>
      <dc:creator>kris1733</dc:creator>
      <dc:date>2023-10-10T17:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate error percentage of HTTPStatus</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660274#M227921</link>
      <description>&lt;P&gt;Remove all the ticks/quotes from the field names in your SPL - for what you are doing they aren't necessary.&amp;nbsp; I only quote my field names if they have any negative space characters.&amp;nbsp; Once I did that I was able to "fake" your search in my environment and get results:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal status=*
| rename status AS HTTPStatus
| stats count(eval(HTTPStatus &amp;gt;= 400 AND HTTPStatus &amp;lt; 500)) AS fourxxErrors, count(eval(HTTPStatus &amp;gt;= 500 AND HTTPStatus &amp;lt; 600)) AS fivexxErrors, count AS TotalRequests
| eval fourxxPercentage = if(TotalRequests &amp;gt; 0, (fourxxErrors / TotalRequests) * 100, 0), fivexxPercentage = if(TotalRequests &amp;gt; 0, (fivexxErrors / TotalRequests) * 100, 0)
| table fourxxPercentage, fivexxPercentage&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I just added this at the beginning to turn misc data in _internal into events that "look" like yours for this example purpose:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal status=*
| rename status AS HTTPStatus&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 18:47:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660274#M227921</guid>
      <dc:creator>_JP</dc:creator>
      <dc:date>2023-10-10T18:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate error percentage of HTTPStatus</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660276#M227922</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261258"&gt;@_JP&lt;/a&gt;&amp;nbsp;Hi, the query which you shared me works same like the one which I shared. The percentage values are showing 0. Is it because we need to add decimal values after 0. I tried adding&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(fourxxErrors / TotalRequests) * 100, 2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(fourxxErrors / TotalRequests) * 100, 0)&lt;/PRE&gt;&lt;P&gt;But no use. Do you have any other idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 18:57:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660276#M227922</guid>
      <dc:creator>kris1733</dc:creator>
      <dc:date>2023-10-10T18:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate error percentage of HTTPStatus</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660281#M227923</link>
      <description>&lt;P&gt;I don't have any 500's in my _internal index (this is not a flex...just a fresh install before I have had a chance to break anything).&amp;nbsp; So this is what my results look like:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="no_500.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27512iCD88970B5815952E/image-size/large?v=v2&amp;amp;px=999" role="button" title="no_500.png" alt="no_500.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe for the timerange you don't have any 5xx errors?&amp;nbsp; If I flub the query a little more in my environment and change the boolean criteria a bit in the SPL to be &amp;gt;=300&amp;lt;400 (see highlighted section) then it works correctly for me:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_JP_0-1696964434755.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/27511i54A0B380E351BC76/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_JP_0-1696964434755.png" alt="_JP_0-1696964434755.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 19:03:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660281#M227923</guid>
      <dc:creator>_JP</dc:creator>
      <dc:date>2023-10-10T19:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate error percentage of HTTPStatus</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660325#M227936</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261258"&gt;@_JP&lt;/a&gt;&amp;nbsp;is correct that single quotes have special meaning in SPL. &amp;nbsp;Have you tested&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal status=*
| rename status AS HTTPStatus
| stats count(eval(HTTPStatus &amp;gt;= 400 AND HTTPStatus &amp;lt; 500)) AS fourxxErrors, count(eval(HTTPStatus &amp;gt;= 500 AND HTTPStatus &amp;lt; 600)) AS fivexxErrors, count AS TotalRequests&lt;/LI-CODE&gt;&lt;P&gt;Can you share sample output from this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 23:10:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-error-percentage-of-HTTPStatus/m-p/660325#M227936</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-10-10T23:10:41Z</dc:date>
    </item>
  </channel>
</rss>

