<?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 calculate time base difference on data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520717#M146690</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get the results following your instruction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I'm pretty not sure if I'm doing it right. I don't get the difference result with below search command&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MY_SEARCH_COMMAND | bin _time span=1d
| eval resource_a_total = a_val * threshold
| eval resource_a_total = b_val * threshold
| stats sum(resource_a_used) as a_used, sum(resource_a_total) as a_total, sum(resource_b_used) as b_used, sum(resource_b_total) as b_total by _time cluster
| eval a_usage =round(a_used / a_total * 100, 2)
| eval b_usage =round(a_used / a_total * 100, 2)
| autoregress a_usage p=1
| eval a_diff = a_usage - a_usage_1
| table name a_usage a_diff b_usage&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 22 Sep 2020 02:42:23 GMT</pubDate>
    <dc:creator>splunkkid</dc:creator>
    <dc:date>2020-09-22T02:42:23Z</dc:date>
    <item>
      <title>How to calculate time base difference on data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520566#M146563</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am currently struggling with some SPL search command..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to show on table about resource's usage data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The current spl command is like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MY_SEARCH_COMMAND 
| eval resource_a_total = a_val * threshold
| eval resource_a_total = b_val * threshold
| stats sum(resource_a_used) as a_used, sum(resource_a_total) as a_total, sum(resource_b_used) as b_used, sum(resource_b_total) as b_total by cluster
| eval a_usage =round(a_used / a_total * 100, 2)
| eval b_usage =round(a_used / a_total * 100, 2)
| table name a_usage b_usage&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, to get usage data, have to calculate each hosts total / used data value and then do aggregation based on same cluster name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this situation, I want&amp;nbsp; to add difference of usage data from yesterday to today. If yesterday's resource_a usage is bigger than today, then table should write resource_a_diff like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; a_usage&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; a_diff&amp;nbsp; |&amp;nbsp; b_usage&amp;nbsp; &amp;nbsp;|&amp;nbsp; b_diff&lt;/P&gt;&lt;P&gt;clusterA&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;80&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp;-5%p&amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 70&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;5%p&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I write the statement as efficient way?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 08:01:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520566#M146563</guid>
      <dc:creator>splunkkid</dc:creator>
      <dc:date>2020-09-21T08:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time base difference on data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520571#M146566</link>
      <description>&lt;P&gt;Obviously, you need to add a time element to your stats with a span of 1d, then you could consider autoregress to get the previous day's stats and do your calculations using those values.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 08:55:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520571#M146566</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2020-09-21T08:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time base difference on data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520717#M146690</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get the results following your instruction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I'm pretty not sure if I'm doing it right. I don't get the difference result with below search command&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MY_SEARCH_COMMAND | bin _time span=1d
| eval resource_a_total = a_val * threshold
| eval resource_a_total = b_val * threshold
| stats sum(resource_a_used) as a_used, sum(resource_a_total) as a_total, sum(resource_b_used) as b_used, sum(resource_b_total) as b_total by _time cluster
| eval a_usage =round(a_used / a_total * 100, 2)
| eval b_usage =round(a_used / a_total * 100, 2)
| autoregress a_usage p=1
| eval a_diff = a_usage - a_usage_1
| table name a_usage a_diff b_usage&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 02:42:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520717#M146690</guid>
      <dc:creator>splunkkid</dc:creator>
      <dc:date>2020-09-22T02:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time base difference on data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520741#M146697</link>
      <description>&lt;P&gt;The autoregress field name has a p in it&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MY_SEARCH_COMMAND | bin _time span=1d
| eval resource_a_total = a_val * threshold
| eval resource_a_total = b_val * threshold
| stats sum(resource_a_used) as a_used, sum(resource_a_total) as a_total, sum(resource_b_used) as b_used, sum(resource_b_total) as b_total by _time cluster
| eval a_usage =round(a_used / a_total * 100, 2)
| eval b_usage =round(a_used / a_total * 100, 2)
| autoregress a_usage p=1
| eval a_diff = a_usage - a_usage_p1
| table name a_usage a_diff b_usage&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 07:16:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520741#M146697</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2020-09-22T07:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time base difference on data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520764#M146701</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe I'm not fully understand about the commands although I read documentation regarding that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed the command as you specified and the result is not quite as I want.&lt;/P&gt;&lt;P&gt;The current result is like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; a_usage&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; a_diff&amp;nbsp; |&amp;nbsp; b_usage&amp;nbsp; &amp;nbsp;|&amp;nbsp; b_diff&lt;/P&gt;&lt;P&gt;clusterA&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;80&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; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 70&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;clusterB&amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-5%p&amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;65&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; -5%p&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like this, the difference data is not based on time, but based on prior data that written right above of it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;(clusterB 's a_diff is calculated as (clusterB's a_uage - clusterA's a_usage))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 09:07:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520764#M146701</guid>
      <dc:creator>splunkkid</dc:creator>
      <dc:date>2020-09-22T09:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time base difference on data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520769#M146702</link>
      <description>&lt;P&gt;You probably need to change the order of the fields you are grouping by in the stats command. You should also remove the first for each cluster. Also, should b_usage be based on a?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MY_SEARCH_COMMAND | bin _time span=1d
| eval resource_a_total = a_val * threshold
| eval resource_a_total = b_val * threshold
| stats sum(resource_a_used) as a_used, sum(resource_a_total) as a_total, sum(resource_b_used) as b_used, sum(resource_b_total) as b_total by cluster _time
| eval a_usage =round(a_used / a_total * 100, 2)
| eval b_usage =round(b_used / b_total * 100, 2)
| autoregress a_usage p=1
| eventstats first(_time) as firsttime by cluster
| where _time != firsttime
| eval a_diff = a_usage - a_usage_p1
| table name a_usage a_diff b_usage&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 09:39:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-time-base-difference-on-data/m-p/520769#M146702</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2020-09-22T09:39:21Z</dc:date>
    </item>
  </channel>
</rss>

