<?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: Summing epoch values within a JSON field in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319512#M59682</link>
    <description>&lt;P&gt;@Esky73 - interesting.  &lt;/P&gt;

&lt;P&gt;I would have done this, but your way is fine.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | eval duration=tonumber(mvindex(stoptime,myFan)) - tonumber(mvindex(starttime,myFan))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Updated the answer to fix the typo and add the the &lt;CODE&gt;tonumber()&lt;/CODE&gt; typing.&lt;/P&gt;

&lt;P&gt;Please accept the answer so it will show as closed.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2017 00:28:45 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-10-23T00:28:45Z</dc:date>
    <item>
      <title>Summing epoch values within a JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319508#M59678</link>
      <description>&lt;P&gt;I have ingested a JSON file which shows me how long spent on an app on my phone and looks like (below)&lt;BR /&gt;
The fields have been extracted using KV_MODE = json which extracts the fields.&lt;BR /&gt;
The "tc" field consists of arrays of start epoch time and stop epoch time.&lt;BR /&gt;
Looking for a way to calculate the duration between start and stop time and sum the totals of the time pairs ?&lt;/P&gt;

&lt;P&gt;{ "id": "4bd3f831", "pn": "com.mixcloud.player414", "pvc": "414", "tc": [ [ 1508278704589, 1508278705604 ], [ 1508278705751, 1508278707123 ], [ 1508278707180, 1508278708056 ], [ 1508278708101, 1508278708927 ], [ 1508278709604, 1508278716390 ], [ 1508278836263, 1508278837301 ], [ 1508278837693, 1508278851610 ], [ 1508278861521, 1508278862569 ], [ 1508278862931, 1508278868520 ], [ 1508302373918, 1508302374962 ], [ 1508302375336, 1508302383102 ], [ 1508363224848, 1508363225862 ], [ 1508363226458, 1508363235766 ], [ 1508404509296, 1508404510357 ], [ 1508404510843, 1508404520545 ], [ 1508404520674, 1508404528311 ] ] },&lt;/P&gt;

&lt;P&gt;Thx.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 03:03:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319508#M59678</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2017-10-20T03:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summing epoch values within a JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319509#M59679</link>
      <description>&lt;P&gt;Try this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats count as recno
| appendpipe 
    [| fields recno 
     | rex field=_raw "\[\s*(?&amp;lt;starttime&amp;gt;\d+),\s*(?&amp;lt;stoptime&amp;gt;\d+)\s*\]" max_match=0
     | eval myFan=mvrange(0,mvcount(starttime)) 
     | mvexpand myFan 
     | eval duration=tonumber(mvindex(stoptime,myFan)) - tonumber(mvindex(starttime,myFan))
     | stats sum(duration) as duration count as killme by recno
    ]
| eventstats values(duration)  as duration by recno
| where isnull(killme)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;updated typo &lt;CODE&gt;+*&lt;/CODE&gt; to &lt;CODE&gt;*&lt;/CODE&gt;, updated &lt;CODE&gt;eval duration&lt;/CODE&gt; to use &lt;CODE&gt;tonumber()&lt;/CODE&gt; on the results before subtracting.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 04:32:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319509#M59679</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-20T04:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Summing epoch values within a JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319510#M59680</link>
      <description>&lt;P&gt;Thanks @DalJeanis .. there was a slight typo in the rex cmd :&lt;BR /&gt;
amended to - &lt;CODE&gt;rex field=_raw "\[\s*(?\d+),\s*(?\d+)\s*\]" max_match=0&lt;/CODE&gt;&lt;BR /&gt;
But now i see the following error ..&lt;BR /&gt;
Error in 'eval' command: Typechecking failed. '-' only takes numbers.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 05:12:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319510#M59680</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2017-10-20T05:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Summing epoch values within a JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319511#M59681</link>
      <description>&lt;P&gt;separated the eval cmd which worked with the following - thx ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test pn="*"
| streamstats count as recno 
| appendpipe 
    [| fields recno 
    | rex field=_raw "\[\s*(?&amp;lt;starttime&amp;gt;\d+),\s*(?&amp;lt;stoptime&amp;gt;\d+)\s*\]" max_match=0 
    | eval myFan=mvrange(0,mvcount(starttime)) 
    | mvexpand myFan 
    | eval stopduration=mvindex(stoptime,myFan) 
    | eval startduration=mvindex(starttime,myFan) 
    | eval duration=stopduration-startduration 
    | stats sum(duration) as duration count as killme by recno
    ] 
| eventstats values(duration) as duration by recno 
| where isnull(killme)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Oct 2017 22:33:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319511#M59681</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2017-10-22T22:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Summing epoch values within a JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319512#M59682</link>
      <description>&lt;P&gt;@Esky73 - interesting.  &lt;/P&gt;

&lt;P&gt;I would have done this, but your way is fine.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | eval duration=tonumber(mvindex(stoptime,myFan)) - tonumber(mvindex(starttime,myFan))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Updated the answer to fix the typo and add the the &lt;CODE&gt;tonumber()&lt;/CODE&gt; typing.&lt;/P&gt;

&lt;P&gt;Please accept the answer so it will show as closed.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 00:28:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319512#M59682</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-23T00:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Summing epoch values within a JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319513#M59683</link>
      <description>&lt;P&gt;With the output from the above search - how to sum the duration of the same processes so sum of com.teslcoilsw.launcher.* and sum of com.facebook.katana.* ?&lt;/P&gt;

&lt;P&gt;1   com.teslacoilsw.launcher54100   391.27&lt;BR /&gt;
2   com.teslacoilsw.launcher54100   382.81&lt;BR /&gt;
3   com.teslacoilsw.launcher54100   285.94&lt;BR /&gt;
4   com.teslacoilsw.launcher53000   270.90&lt;BR /&gt;
5   com.facebook.katana75931115 102.39&lt;BR /&gt;
6   com.whatsapp452018  89.20&lt;BR /&gt;
7   com.facebook.katana75931115 75.37&lt;BR /&gt;
8   com.facebook.katana74851857 58.64&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 23:59:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Summing-epoch-values-within-a-JSON-field/m-p/319513#M59683</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2017-11-02T23:59:38Z</dc:date>
    </item>
  </channel>
</rss>

