<?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 How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425214#M121922</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to get a timeline of the percentage of a particular error code among the total of logs. And, based on some of the questions around the topic, I've been essentially trying two approaches. The first one I'm not even able to get working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="logger" "Log Info" 
| bin _time span=1h
| eval _raw=replace(_raw,"\\\\\"","\"")
| rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
| eval json= raw_request
| spath input=json output=country_code path=customer.billingAddress.countryCode
| spath input=json output=reason_code path=history{}.reasonCode
| eval error=if(like(reason_code,"%X201%"),1,0)
| stats count as total by _time, country_code
| eventstats sum(error) as errors by _time
| eval error_percentage=100*errors/total 
| timechart span=1h max(error_percentage) by country_code
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;Errors&lt;/CODE&gt; is not even populated (edit, placing the &lt;CODE&gt;eval error...&lt;/CODE&gt; after the &lt;CODE&gt;stats count...&lt;/CODE&gt; populates it but shows 0 in all cases)&lt;/P&gt;

&lt;P&gt;Looks that the second approach works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="logger" "Log Info"
| eval _raw=replace(_raw,"\\\\\"","\"")
| rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
| eval json= raw_request
| spath input=json output=country_code path=customer.billingAddress.countryCode
| spath input=json output=reason_code path=history{}.reasonCode
| eval error=if(like(reason_code,"%X201%"),1,0)
| streamstats count as total sum(error) as errors by country_code
| timechart span=1h max(eval(100*errors/total)) as error_percentage by country_code usenull=f useother=f
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But, if I change &lt;CODE&gt;max&lt;/CODE&gt; for &lt;CODE&gt;avg&lt;/CODE&gt; , I don't get the same result. I think that should be the case if I had one entry per bucket and country_code as was my intention&lt;/P&gt;

&lt;P&gt;If I could get some directions around this I would really appreciate that as well if there's an easy way to avoid displaying all the country_codes and just display the ones that at some point of the timeline displayed have gotten an error &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sat, 13 Oct 2018 17:10:49 GMT</pubDate>
    <dc:creator>Esperteyu</dc:creator>
    <dc:date>2018-10-13T17:10:49Z</dc:date>
    <item>
      <title>How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425214#M121922</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to get a timeline of the percentage of a particular error code among the total of logs. And, based on some of the questions around the topic, I've been essentially trying two approaches. The first one I'm not even able to get working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="logger" "Log Info" 
| bin _time span=1h
| eval _raw=replace(_raw,"\\\\\"","\"")
| rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
| eval json= raw_request
| spath input=json output=country_code path=customer.billingAddress.countryCode
| spath input=json output=reason_code path=history{}.reasonCode
| eval error=if(like(reason_code,"%X201%"),1,0)
| stats count as total by _time, country_code
| eventstats sum(error) as errors by _time
| eval error_percentage=100*errors/total 
| timechart span=1h max(error_percentage) by country_code
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;Errors&lt;/CODE&gt; is not even populated (edit, placing the &lt;CODE&gt;eval error...&lt;/CODE&gt; after the &lt;CODE&gt;stats count...&lt;/CODE&gt; populates it but shows 0 in all cases)&lt;/P&gt;

&lt;P&gt;Looks that the second approach works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="logger" "Log Info"
| eval _raw=replace(_raw,"\\\\\"","\"")
| rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
| eval json= raw_request
| spath input=json output=country_code path=customer.billingAddress.countryCode
| spath input=json output=reason_code path=history{}.reasonCode
| eval error=if(like(reason_code,"%X201%"),1,0)
| streamstats count as total sum(error) as errors by country_code
| timechart span=1h max(eval(100*errors/total)) as error_percentage by country_code usenull=f useother=f
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But, if I change &lt;CODE&gt;max&lt;/CODE&gt; for &lt;CODE&gt;avg&lt;/CODE&gt; , I don't get the same result. I think that should be the case if I had one entry per bucket and country_code as was my intention&lt;/P&gt;

&lt;P&gt;If I could get some directions around this I would really appreciate that as well if there's an easy way to avoid displaying all the country_codes and just display the ones that at some point of the timeline displayed have gotten an error &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 17:10:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425214#M121922</guid>
      <dc:creator>Esperteyu</dc:creator>
      <dc:date>2018-10-13T17:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425215#M121923</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/71335"&gt;@Esperteyu&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;Based on your searches, you are considering only the error codes "%X201%" . Also the percentage is based on the errors and not on the total count of country codes, below should gives us a list of country_codes and reason_codes where there is an error exists&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="logger" "Log Info"
 | eval _raw=replace(_raw,"\\\\\"","\"")
 | rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
 | eval json= raw_request
 | spath input=json output=country_code path=customer.billingAddress.countryCode
 | spath input=json output=reason_code path=history{}.reasonCode
 | eval error=if(like(reason_code,"%X201%"),1,0)
 | where error==1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now we plot the count of errors in a timechart &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="logger" "Log Info"
 | eval _raw=replace(_raw,"\\\\\"","\"")
 | rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
 | eval json= raw_request
 | spath input=json output=country_code path=customer.billingAddress.countryCode
 | spath input=json output=reason_code path=history{}.reasonCode
 | eval error=if(like(reason_code,"%X201%"),1,0)
 | where error==1
 | timechart span=1h count by country_code
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now we calculate the percentage for each of the country code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="logger" "Log Info"
 | eval _raw=replace(_raw,"\\\\\"","\"")
 | rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
 | eval json= raw_request
 | spath input=json output=country_code path=customer.billingAddress.countryCode
 | spath input=json output=reason_code path=history{}.reasonCode
 | eval error=if(like(reason_code,"%X201%"),1,0)
 | where error==1
 | timechart span=1h count by country_code
 | addtotals row=true fieldname=_Total
 | foreach * [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; * 100 / _Total]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Lets know if it works&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:36:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425215#M121923</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-09-29T21:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425216#M121924</link>
      <description>&lt;P&gt;Thanks @renjith.nair, I'm not able to follow  the solution specially what is doing in the last line with the equality of the &amp;lt;&amp;gt; but in any case it's not giving a reasonable result. I'm not sure if I had not explained properly my question though, I'm after &lt;CODE&gt;number of X201&lt;/CODE&gt;\total grouped by country_code (the removal of the ones with no errors would be a nice to have). In the case of streamstats I can't understand why max and avg differ, in the case of the first option I'm not sure of following you, I thought eventstats would append a integer to each of the events and then the sum could be grouped by country_code in the same way as the total&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:37:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425216#M121924</guid>
      <dc:creator>Esperteyu</dc:creator>
      <dc:date>2020-09-29T21:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425217#M121925</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/71335"&gt;@Esperteyu&lt;/a&gt;, ok let me try to explain &lt;BR /&gt;
- In the first two SPLs, we have calculated count of errors by country_code in a time window of 1 hr. Could you please confirm if you are able to get the expected values there?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sample result&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    _time                            US UK AU
    2018-10-14 10:15:00   2   4   6
     2018-10-14 11:15:00  3   5    7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using &lt;CODE&gt;addtotals&lt;/CODE&gt; we add up count of all country's for that time window which 12 for first row and 15 for second row&lt;BR /&gt;
Then using  &lt;CODE&gt;foreach&lt;/CODE&gt;, we traverse through the columns and divide each count by  the total of that row which gives you a % for that time window i.e. 2*100/12 , 4*100/12, 6*100/12  etc.&lt;/P&gt;

&lt;P&gt;If this is not what you are looking for, kindly provide some sample data and then the expected output.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:37:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425217#M121925</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-09-29T21:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425218#M121926</link>
      <description>&lt;P&gt;I see, my bad that I didn't explain it properly then. I really appreciate your patience @renjith.nair&lt;BR /&gt;
What I am trying to get is the ratio errors/total per country, something like this (as it's returned from the streamstats versions)&lt;/P&gt;

&lt;P&gt;_time     ARE    AUS    AUT    BGR    BRA    USA&lt;BR /&gt;
t1           0    0.17   0                              0.28&lt;BR /&gt;
t2                0.18   0                          0.28&lt;BR /&gt;
t3        0   0.18   0                          0.28&lt;BR /&gt;
t4        0   0.19   0           0          0         0.28&lt;BR /&gt;
t5        0   0.21   0          0                   0.28&lt;/P&gt;

&lt;P&gt;I guess another acceptable format would be&lt;/P&gt;

&lt;P&gt;_time country_code total errors percentage&lt;BR /&gt;
t1        UK                   100   20        20&lt;BR /&gt;
t1      US                   50     5          10&lt;BR /&gt;
t2      UK                  10      3         30&lt;BR /&gt;
t2      US                   40    10        25   &lt;/P&gt;

&lt;P&gt;With the view of displaying them in the timeline to see how that percentage averages, spikes (I think that brings the concept of running percentage) on a country basis&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:37:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425218#M121926</guid>
      <dc:creator>Esperteyu</dc:creator>
      <dc:date>2020-09-29T21:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425219#M121927</link>
      <description>&lt;P&gt;I have tried to answer to this comment but it has to be reviewed by a moderator (I think it might be because of the "tables" I put), a shorter response with no tables: what I am trying to get is the ratio error/total on a country basis i.e. error per country / total per country in a given period of time (will need to monitor in such running percentage for spikes)&lt;/P&gt;

&lt;P&gt;I was playing around now with this query, which is simpler but works independently of using max or avg and I think it might do the trick although need to double check with enough data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="logger" Log Info
 | bin _time span=1h
 | eval _raw=replace(_raw,"\\\\\"","\"")
 | rex "\"RawRequest\":\"(?&amp;lt;raw_request&amp;gt;.+)\"}$"
 | eval json= raw_request
 | spath input=json output=country_code path=customer.billingAddress.countryCode
 | spath input=json output=reason_code path=history{}.reasonCode
 | eval error=if(like(reason_code,"%X201%"),1,0) 
 | stats count as total sum(error) as errors by _time, country_code
 | eval error_percentage=100*errors/total 
 | timechart span=1h max(error_percentage) by country_code
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sorry for not explained it properly and thanks for your patience @renjith.nair &lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 11:18:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425219#M121927</guid>
      <dc:creator>Esperteyu</dc:creator>
      <dc:date>2018-10-14T11:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425220#M121928</link>
      <description>&lt;P&gt;Alright @Esperteyu . In the above SPL, don't you want the total and sum interchanged? i.e. count as errors , sum(error) as total. &lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 12:50:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425220#M121928</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-14T12:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425221#M121929</link>
      <description>&lt;P&gt;@renjith.nair you  make me doubt now, but I understand the count will bring all the rows and the sum(error) will bring the ones which actually have the "X201" substring so I think it should be like this&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 12:54:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425221#M121929</guid>
      <dc:creator>Esperteyu</dc:creator>
      <dc:date>2018-10-14T12:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get a timeline of the percentage of a particular error code among a total of logs coming into Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425222#M121930</link>
      <description>&lt;P&gt;Ahh sorry for that. I was still  thinking about the rows with errors only (1)but you have both 0 and 1 in errors&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 13:33:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-get-a-timeline-of-the-percentage-of-a-particular-error/m-p/425222#M121930</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-14T13:33:21Z</dc:date>
    </item>
  </channel>
</rss>

