<?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: Finding random() events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116824#M31035</link>
    <description>&lt;P&gt;For a contiguous set of 10 events from a random place in the data you could do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | head [tstats count where index=_internal | eval random = (random() % count) + 1 | return $random] | tail 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;tstats&lt;/CODE&gt; subsearch will &lt;CODE&gt;count&lt;/CODE&gt; the number of events and produce a &lt;CODE&gt;random&lt;/CODE&gt; value in between 1 and count inclusive. That's passed to &lt;CODE&gt;head&lt;/CODE&gt;, retrieving the first &lt;CODE&gt;random&lt;/CODE&gt; number of events... &lt;CODE&gt;tail&lt;/CODE&gt; keeps the last ten. Should be much faster than loading everything, &lt;CODE&gt;streamstats&lt;/CODE&gt; over everything, and sorting - but isn't doing quite the same thing, so both ways are valid.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jun 2014 12:05:49 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-06-24T12:05:49Z</dc:date>
    <item>
      <title>Finding random() events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116823#M31034</link>
      <description>&lt;P&gt;Not so much a question, but an answer to how I found a way to select random "foo" in Splunk.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;your search for foo&lt;BR /&gt;
| eval rnd=random() &lt;BR /&gt;
| sort rnd &lt;BR /&gt;
| streamstats count by foo&lt;BR /&gt;
| where count &amp;lt;=10 &lt;BR /&gt;
| sort foo &lt;BR /&gt;
| table time foo&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This takes your search results, tacks on another field with a random number, sorts by that number (to randomise your results) - then using streamstats it adds a count per "foo" this could be a device, host, ticket number whatever. We then return where that count is &amp;lt;=10 (to get 10 foo), sort by that field to group them together - and viola - a random selection of 10 foo.&lt;/P&gt;

&lt;P&gt;Hope someone finds it as useful as I have.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
Ash&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2014 03:14:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116823#M31034</guid>
      <dc:creator>ahartge</dc:creator>
      <dc:date>2014-06-24T03:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding random() events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116824#M31035</link>
      <description>&lt;P&gt;For a contiguous set of 10 events from a random place in the data you could do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | head [tstats count where index=_internal | eval random = (random() % count) + 1 | return $random] | tail 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;tstats&lt;/CODE&gt; subsearch will &lt;CODE&gt;count&lt;/CODE&gt; the number of events and produce a &lt;CODE&gt;random&lt;/CODE&gt; value in between 1 and count inclusive. That's passed to &lt;CODE&gt;head&lt;/CODE&gt;, retrieving the first &lt;CODE&gt;random&lt;/CODE&gt; number of events... &lt;CODE&gt;tail&lt;/CODE&gt; keeps the last ten. Should be much faster than loading everything, &lt;CODE&gt;streamstats&lt;/CODE&gt; over everything, and sorting - but isn't doing quite the same thing, so both ways are valid.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jun 2014 12:05:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116824#M31035</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-06-24T12:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding random() events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116825#M31036</link>
      <description>&lt;P&gt;Thanks for the comments Martin, and certainly another approach for block of 10 events. I ran that, but received an error &lt;EM&gt;"Error in 'TsidxStats': Missing 'FROM' keyword to specify namespace"&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I was aiming for 10 individual samples across the search, which is the reason for needing the random number against each event. In this scenario, there was only a few 1000 events, so streamstats did not cause too much of a perf hit - but i do get the point against a large set.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jun 2014 03:58:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116825#M31036</guid>
      <dc:creator>ahartge</dc:creator>
      <dc:date>2014-06-28T03:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding random() events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116826#M31037</link>
      <description>&lt;P&gt;They're two different use cases, yeah - just seemed to fit in with the topic &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;As for your &lt;CODE&gt;tstats&lt;/CODE&gt;, be wary of its syntax. It's slightly different and a bit tossed around compared to regular searching: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.1/SearchReference/tstats"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.1/SearchReference/tstats&lt;/A&gt;&lt;BR /&gt;
Also, make sure you look at the right version, it's one of the newer commands.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jun 2014 08:18:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-random-events/m-p/116826#M31037</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-06-28T08:18:31Z</dc:date>
    </item>
  </channel>
</rss>

