<?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: interpolating non matching values before correlating two series in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62721#M180223</link>
    <description>&lt;P&gt;A native Splunk solution, cross-posted from &lt;A href="http://answers.splunk.com/answers/147907/how-to-perform-spectrum-analysis"&gt;http://answers.splunk.com/answers/147907/how-to-perform-spectrum-analysis&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Here's a run-anywhere example using _internal data coming in every 30s, interpolated to 10s:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=_internal eps="*" group=per_host_thruput | head 10 | timechart fixedrange=f span=10s avg(ev) as ev
| eval value_time = case(isnotnull(ev), _time) | streamstats last(ev) as last_ev last(value_time) as last_time | reverse | streamstats last(ev) as next_ev last(value_time) as next_time | reverse
| eval interpolated_ev = last_ev + ((_time - last_time) / (next_time - last_time)) * (next_ev - last_ev)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;First line grabs data and builds a timechart with data gaps in it.&lt;BR /&gt;
Second line prepares lots of data to fill in the gaps: previous value, next value, time of previous value, time of next value&lt;BR /&gt;
Last line calculates the naïve linearly interpolated value.&lt;BR /&gt;
Some results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                ev  interpolated_ev
2014-07-30 00:55:00  99
2014-07-30 00:55:10      98.000000
2014-07-30 00:55:20      97.000000
2014-07-30 00:55:30  96
2014-07-30 00:55:40      101.000000
2014-07-30 00:55:50      106.000000
2014-07-30 00:56:00 111
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Aug 2014 18:33:19 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-08-06T18:33:19Z</dc:date>
    <item>
      <title>interpolating non matching values before correlating two series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62719#M180221</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
We want to produce correlations between two different (timestamp,value) series. We basically want to plot one value against the other and show the results on a chart.&lt;BR /&gt;
We can get the data we want in a table like this:&lt;/P&gt;

&lt;P&gt;timestamp,value1,value2&lt;BR /&gt;
123456789,x1,y1&lt;BR /&gt;
123456790,x2,&lt;BR /&gt;
123456800,,y3&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;As you can see in the example above, we can have gaps (nulls) in the data, corresponding to timestamps when either one or the other series does not have a recorded value.&lt;/P&gt;

&lt;P&gt;Can Splunk fill in those gaps by interpolating the missing values? How?&lt;/P&gt;

&lt;P&gt;After doing this we would get a table like this:&lt;/P&gt;

&lt;P&gt;timestamp,value1,value2&lt;BR /&gt;
123456789,x1,y1&lt;BR /&gt;
123456790,x2,y2_interp&lt;BR /&gt;
123456800,x3_interp,y3&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;where x3_interp and y2_interp are values obtained by doing some interpolation on the x and y series (Spline, linear etc).&lt;/P&gt;

&lt;P&gt;The we would apply "| chart v1 by v2" to see the graph.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
Alex&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:31:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62719#M180221</guid>
      <dc:creator>SunDance</dc:creator>
      <dc:date>2020-09-28T13:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: interpolating non matching values before correlating two series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62720#M180222</link>
      <description>&lt;P&gt;I came upon this while searching for interpolation solution myself.  After comparing your use case and my own, I come to the following.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;If value space is continuous and spline is appropriate, R provides several spline functions (but not linear) for constant-rate data; CRAN (R's equivalent to CPAN) offers several spline functions (including linear) for variable-rate data.  As @martin_mueller kindly pointed out, R offers an &lt;A href="http://apps.splunk.com/app/1735/"&gt;app in Splunk&lt;/A&gt;.  I believe that you can write your own interpolation function by creating &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.2/AdvancedDev/SearchScripts"&gt;custom search commands&lt;/A&gt;, too.&lt;/LI&gt;
&lt;LI&gt;If value space is discrete and missing values should be interpreted as 0, it depends on sampling rate.  Nothing needs to be done (except filling missing values with 0) if sampling rate is constant.  If not, Splunk's own &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.2/SearchReference/timechart"&gt;timechart&lt;/A&gt; function can provide an approximation for linear interpolation. (See &lt;A href="http://answers.splunk.com/answer_link/149598/"&gt;this answer&lt;/A&gt; by @somesoni2 for a complete solution to fill in the blanks when sampling rate is variable.)&lt;/LI&gt;
&lt;LI&gt;If value space is discrete and missing values must not be interpreted as 0, interpolation using custom search command is perhaps the best option.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 29 Jul 2014 21:16:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62720#M180222</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2014-07-29T21:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: interpolating non matching values before correlating two series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62721#M180223</link>
      <description>&lt;P&gt;A native Splunk solution, cross-posted from &lt;A href="http://answers.splunk.com/answers/147907/how-to-perform-spectrum-analysis"&gt;http://answers.splunk.com/answers/147907/how-to-perform-spectrum-analysis&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Here's a run-anywhere example using _internal data coming in every 30s, interpolated to 10s:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=_internal eps="*" group=per_host_thruput | head 10 | timechart fixedrange=f span=10s avg(ev) as ev
| eval value_time = case(isnotnull(ev), _time) | streamstats last(ev) as last_ev last(value_time) as last_time | reverse | streamstats last(ev) as next_ev last(value_time) as next_time | reverse
| eval interpolated_ev = last_ev + ((_time - last_time) / (next_time - last_time)) * (next_ev - last_ev)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;First line grabs data and builds a timechart with data gaps in it.&lt;BR /&gt;
Second line prepares lots of data to fill in the gaps: previous value, next value, time of previous value, time of next value&lt;BR /&gt;
Last line calculates the naïve linearly interpolated value.&lt;BR /&gt;
Some results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                ev  interpolated_ev
2014-07-30 00:55:00  99
2014-07-30 00:55:10      98.000000
2014-07-30 00:55:20      97.000000
2014-07-30 00:55:30  96
2014-07-30 00:55:40      101.000000
2014-07-30 00:55:50      106.000000
2014-07-30 00:56:00 111
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Aug 2014 18:33:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/interpolating-non-matching-values-before-correlating-two-series/m-p/62721#M180223</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-06T18:33:19Z</dc:date>
    </item>
  </channel>
</rss>

