<?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: Compare two values from different time ranges and get a percentage to trigger an alert in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/602986#M49527</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/247139"&gt;@sohaib112&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-7d latest=now 
| eval kind=if(_time&amp;gt;now()-900,"fifteen_mins","seven_days")
| stats 
   avg(eval(if(kind="fifteen_minutes",avg_rt,""))) AS fifteen_minutes
   avg(eval(if(kind="seven_days",avg_rt,""))) AS seven_days
| eval Result = ((fifteen_mins/seven_days)*100) 
| where Result&amp;gt;50&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 11:21:41 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2022-06-23T11:21:41Z</dc:date>
    <item>
      <title>How to compare two values from different time ranges and get a percentage to trigger an alert?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/602976#M49526</link>
      <description>&lt;P&gt;I am trying to compare avg_rt for uWSGI workers for the last 15 mins and the last 7 days and then get a percentage out of it. If the difference is more than 50% then I want to trigger an alert.&lt;/P&gt;
&lt;P&gt;Here is my search&lt;/P&gt;
&lt;P&gt;host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-7d latest=now | stats avg(avg_rt) AS seven_days | append [ search host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-15m latest=now | stats avg(avg_rt) AS fifteen_mins ] | eval Result = (( fifteen_mins / seven_days ) * 100 ) | where Result &amp;gt; 50&lt;/P&gt;
&lt;P&gt;I am unable to get a Result for whatever number I choose. it is not able to execute this part&lt;BR /&gt;&lt;BR /&gt;| eval Result = (( fifteen_mins / seven_days ) * 100 ) | where Result &amp;gt; 50&lt;BR /&gt;&lt;BR /&gt;I am getting values for fifteen_mins and seven_days&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;seven_days&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;fifteen_mins&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;320588.43640873017&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;360114.4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 20:49:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/602976#M49526</guid>
      <dc:creator>sohaib112</dc:creator>
      <dc:date>2022-06-23T20:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from different time ranges and get a percentage to trigger an alert</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/602986#M49527</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/247139"&gt;@sohaib112&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-7d latest=now 
| eval kind=if(_time&amp;gt;now()-900,"fifteen_mins","seven_days")
| stats 
   avg(eval(if(kind="fifteen_minutes",avg_rt,""))) AS fifteen_minutes
   avg(eval(if(kind="seven_days",avg_rt,""))) AS seven_days
| eval Result = ((fifteen_mins/seven_days)*100) 
| where Result&amp;gt;50&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 11:21:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/602986#M49527</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-06-23T11:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from different time ranges and get a percentage to trigger an alert</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/603052#M49541</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;It is not able to calculate the value for fifteen minutes. Hence the result value is empty.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 17:19:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/603052#M49541</guid>
      <dc:creator>sohaib112</dc:creator>
      <dc:date>2022-06-23T17:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from different time ranges and get a percentage to trigger an alert</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/603058#M49544</link>
      <description>&lt;P&gt;Well, this is understandable. You're using append so Splunk adds one set of results (in this case - a single row) to another set (again - a single row). Since each row has differently named column, you get your "chessboard" &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You can't do eval from two different rows (unless you do something with your results first of course).&lt;/P&gt;&lt;P&gt;There are several ways to tackle this. One is using plain stats with conditional evaluation&lt;/P&gt;&lt;PRE&gt;host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-7d latest=now &lt;BR /&gt;| stats avg(eval(if(now()-_time&amp;lt;900,avg_rt,null())) as fifteen_minutes avg(avg_rt) as seven_day&lt;/PRE&gt;&lt;P&gt;Another way would be to do something similar to your idea (although I don't like using separate searches and appending them - waste of a good search ;))&lt;/P&gt;&lt;P&gt;Just do it like you did before but name both results the same. Add to each of them a label field. Ahd use transpose to switch from two rows to two fields in one row.&lt;/P&gt;&lt;P&gt;Another - a bit mor excentric - idea could be to first bin your data to 15 minute long buckets - you're lucky that 7 days divide evenly into 15-minute periods. Do a separate sum and count for each bucket, count the buckets, sum up all bucket counts and sums into two new field, and calculate your averages from just the last bucket. Hey, I quite like that idea &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-7d latest=now&lt;BR /&gt;| bin _time span=15m&lt;BR /&gt;| stats sum(avg_rt) as fifteensum count(avg_rt) as fifteencount by _time&lt;BR /&gt;| sort - _time&lt;BR /&gt;| streamstats count as bucketcount&lt;BR /&gt;| eventstats sum(fifteensum) as weeksum sum(fifteencount) as weekcount&lt;BR /&gt;| where bucketcount=1&lt;BR /&gt;| eval fifteenavg=fifteensum/fifteencount&lt;BR /&gt;| eval weekavg=weeksum/weekcount&lt;/PRE&gt;&lt;P&gt;There are often many different approaches you can take with Splunk &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 18:21:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/603058#M49544</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-06-23T18:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare two values from different time ranges and get a percentage to trigger an alert?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/603149#M49550</link>
      <description>&lt;P&gt;This works for me: host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-7d latest=now | stats avg(avg_rt) AS seven_days | appendcols [ search host="prod-web-02" source="/var/log/uwsgi/app/uwsgi-metrics.log" earliest=-15m latest=now | stats avg(avg_rt) AS fifteen_mins ] | eval result = (round((fifteen_mins/seven_days)*100,2)) | where result &amp;lt; 50 or result &amp;gt; 150&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 10:48:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-compare-two-values-from-different-time-ranges-and-get-a/m-p/603149#M49550</guid>
      <dc:creator>sohaib112</dc:creator>
      <dc:date>2022-06-24T10:48:41Z</dc:date>
    </item>
  </channel>
</rss>

