<?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: Plotting trendlines into the future in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74515#M4004</link>
    <description>&lt;P&gt;In order to do this we can start with 2 macros:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# macros.conf
[lineartrend(2)]
args = x, y
description = Develop a linear trendline against a data set
definition = eventstats count as numevents sum($x$) as sumX sum($y$) as sumY sum(eval($x$*$y$)) as sumXY sum(eval($x$*$x$)) as sumX2 sum(eval($y$*$y$)) as sumY2 
  | eval slope=((numevents*sumXY)-(sumX*sumY))/((numevents*sumX2)-(sumX*sumX)) 
  | eval yintercept=(sumY-(slope*sumX))/numevents 
  | eval newY=(yintercept + (slope*$x$) - 5) 
  | eval R=((numevents*sumXY) - (sumX*sumY))/sqrt(((numevents*sumX2)-(sumX*sumX))*((numevents*sumY2)-(sumY*sumY))) 
  | eval R2=R*R

[extendtrend(2)]
args = newY, end
description = For use after something like lineartrend(2).  Extend the trendline into the future.
definition = append [gentimes start=1 end=$end$ | rename starttime as _time | fields _time] 
  | delta $newY$ as newY_delta 
  | eventstats avg(newY_delta) as avg_newY_delta last($newY$) as lastY 
  | eval pred_accum=if(isnull($newY$), avg_newY_delta, 0) 
  | accum pred_accum 
  | eval newY=if(isnull($newY$), pred_accum + lastY, $newY$)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For the &lt;EM&gt;lineartrend(2)&lt;/EM&gt; macro, you pass in the time field (x value) as well as the numerical value (y value) of the data which is being plotted (in this case the count of events).  This will create a new numerical field called &lt;EM&gt;newY&lt;/EM&gt; which will be the y values for the trendline.  However, the new trendline will only be plotted until "now".  In order to extend it into the future we'll use the &lt;EM&gt;extendtrend(2)&lt;/EM&gt; macro.  For this macro, you pass the newY field (y value to plot) as well as the number of days to project into the future.  The x value (timeline) will be created using &lt;EM&gt;gentimes&lt;/EM&gt;.&lt;/P&gt;

&lt;P&gt;The final search will look like this and includes a high and low threshold in order to show the intersection of the trend:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=syslog | timechart count 
  | `lineartrend(_time, count)` 
  | `extendtrend(newY, 7)` 
  | eval low_threshold=5000 
  | eval high_threshold=50000 
  | timechart values(count) as events values(newY) as linear_trend values(low_threshold) as low_threshold values(high_threshold) as high_threshold
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result should look something like this where the blue line is the plotted syslog event counts ending today, the yellow line is the trendline, which extends beyond today, and the high and low threshold lines:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/krn29.png" alt="http://i.imgur.com/krn29.png" /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Apr 2011 04:56:47 GMT</pubDate>
    <dc:creator>mw</dc:creator>
    <dc:date>2011-04-05T04:56:47Z</dc:date>
    <item>
      <title>Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74514#M4003</link>
      <description>&lt;P&gt;I'd like to plot a numerical value over time (such as syslog event counts), along with a linear trendline (such as this: &lt;A href="http://www.splunk.com/wiki/Community:Plotting_a_linear_trendline" rel="nofollow"&gt;http://www.splunk.com/wiki/Community:Plotting_a_linear_trendline&lt;/A&gt;), but how can I extend the trendline into the future in order to predict approximately what the numerical value would be &lt;EM&gt;n&lt;/EM&gt; days from now? &lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2011 04:40:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74514#M4003</guid>
      <dc:creator>mw</dc:creator>
      <dc:date>2011-04-05T04:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74515#M4004</link>
      <description>&lt;P&gt;In order to do this we can start with 2 macros:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# macros.conf
[lineartrend(2)]
args = x, y
description = Develop a linear trendline against a data set
definition = eventstats count as numevents sum($x$) as sumX sum($y$) as sumY sum(eval($x$*$y$)) as sumXY sum(eval($x$*$x$)) as sumX2 sum(eval($y$*$y$)) as sumY2 
  | eval slope=((numevents*sumXY)-(sumX*sumY))/((numevents*sumX2)-(sumX*sumX)) 
  | eval yintercept=(sumY-(slope*sumX))/numevents 
  | eval newY=(yintercept + (slope*$x$) - 5) 
  | eval R=((numevents*sumXY) - (sumX*sumY))/sqrt(((numevents*sumX2)-(sumX*sumX))*((numevents*sumY2)-(sumY*sumY))) 
  | eval R2=R*R

[extendtrend(2)]
args = newY, end
description = For use after something like lineartrend(2).  Extend the trendline into the future.
definition = append [gentimes start=1 end=$end$ | rename starttime as _time | fields _time] 
  | delta $newY$ as newY_delta 
  | eventstats avg(newY_delta) as avg_newY_delta last($newY$) as lastY 
  | eval pred_accum=if(isnull($newY$), avg_newY_delta, 0) 
  | accum pred_accum 
  | eval newY=if(isnull($newY$), pred_accum + lastY, $newY$)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For the &lt;EM&gt;lineartrend(2)&lt;/EM&gt; macro, you pass in the time field (x value) as well as the numerical value (y value) of the data which is being plotted (in this case the count of events).  This will create a new numerical field called &lt;EM&gt;newY&lt;/EM&gt; which will be the y values for the trendline.  However, the new trendline will only be plotted until "now".  In order to extend it into the future we'll use the &lt;EM&gt;extendtrend(2)&lt;/EM&gt; macro.  For this macro, you pass the newY field (y value to plot) as well as the number of days to project into the future.  The x value (timeline) will be created using &lt;EM&gt;gentimes&lt;/EM&gt;.&lt;/P&gt;

&lt;P&gt;The final search will look like this and includes a high and low threshold in order to show the intersection of the trend:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=syslog | timechart count 
  | `lineartrend(_time, count)` 
  | `extendtrend(newY, 7)` 
  | eval low_threshold=5000 
  | eval high_threshold=50000 
  | timechart values(count) as events values(newY) as linear_trend values(low_threshold) as low_threshold values(high_threshold) as high_threshold
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The result should look something like this where the blue line is the plotted syslog event counts ending today, the yellow line is the trendline, which extends beyond today, and the high and low threshold lines:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/krn29.png" alt="http://i.imgur.com/krn29.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2011 04:56:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74515#M4004</guid>
      <dc:creator>mw</dc:creator>
      <dc:date>2011-04-05T04:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74516#M4005</link>
      <description>&lt;P&gt;If I were to increase the linear trend Line to a future date, like another month, basically what I want is to have the flexibility to choose a specified future date for the trend Line&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2011 23:58:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74516#M4005</guid>
      <dc:creator>Dark_Ichigo</dc:creator>
      <dc:date>2011-12-04T23:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74517#M4006</link>
      <description>&lt;P&gt;Thanks for this information it help me quite a bit, however I noticed that the extendtrend macro provided doesn't work properly unless you are searching with a bucket span of 1 day. &lt;/P&gt;

&lt;P&gt;I used the following macro which gave me a more accurate picture.&lt;/P&gt;

&lt;P&gt;[lineartrendextend(3)]&lt;BR /&gt;
args = x, y, end&lt;BR /&gt;
description = Extends lineartrend(2), x and y should match the args provided to lineartrend, end should be the number of days into the future you would like to extend the trend.&lt;BR /&gt;
definition = append [ gentimes start=1 end=$end$ |rename starttime as _time | fields _time] |eventstats values(yintercept) as yintercept, values(slope) as slope, values(numevents) as numevents | eval newY=(yintercept + (slope * _time)) | fields _time, $y$, newY&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2012 16:49:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74517#M4006</guid>
      <dc:creator>cpayne_satisnet</dc:creator>
      <dc:date>2012-07-02T16:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74518#M4007</link>
      <description>&lt;P&gt;I'm not sure why this isn't working for me, I'm assuming it's because the search query provided above isn't meant to be used verbatim. I'm just not sure what to replace with what. This is the error I'm getting: &lt;/P&gt;

&lt;P&gt;Error in 'eventstats' command: You must specify a rename for the aggregation specifier on the dynamically evaluated field 'sum(eval(count*count))'.&lt;BR /&gt;
Linear&lt;/P&gt;

&lt;P&gt;I have a field called 'action' and I'm trying to trend a certain action to see where it will be in the next month.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 17:50:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74518#M4007</guid>
      <dc:creator>rps462</dc:creator>
      <dc:date>2012-07-12T17:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74519#M4008</link>
      <description>&lt;P&gt;Greetings, I just wanted to mention that there is one small error based on a traditional linear regression. Specifically the line: | eval newY=(yintercept + (slope*$x$) - 5) , the "-5" doesn't do much, and if anything, can cause problems if you are using a small data set that hasn't changed. For example, if you have a series of 4's, it will show newY as -1.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2013 20:53:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74519#M4008</guid>
      <dc:creator>msarro</dc:creator>
      <dc:date>2013-07-17T20:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74520#M4009</link>
      <description>&lt;P&gt;You know what worked for me? Using it with the predict command. The predict command will fill in your data set into the future. After that, you can easily use the trendline command on the field that contains the newly added forecast from the predict command.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2014 20:03:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74520#M4009</guid>
      <dc:creator>whopper</dc:creator>
      <dc:date>2014-03-11T20:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting trendlines into the future</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74521#M4010</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;
Can you give us an example please? &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 20:51:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Plotting-trendlines-into-the-future/m-p/74521#M4010</guid>
      <dc:creator>cttorres</dc:creator>
      <dc:date>2017-08-10T20:51:34Z</dc:date>
    </item>
  </channel>
</rss>

