<?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: Calculate where criteria with value from a subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552236#M156719</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;When using appendcols, you need to be 100% certain that the number of rows in your outer search and the number of rows in the subsearch are the same, otherwise the columns will not necessarily line up with the correct, in your case, host.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Understood. Part of what I've excluded is a couple of lookups done to ensure that the host list is always the same and in the same order.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 19 May 2021 16:00:27 GMT</pubDate>
    <dc:creator>jheiselman</dc:creator>
    <dc:date>2021-05-19T16:00:27Z</dc:date>
    <item>
      <title>Calculate where criteria with value from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552082#M156676</link>
      <description>&lt;P&gt;I'm sure this has been asked before, but nothing I'm coming up with for searches against this forum have proved useful.&lt;/P&gt;&lt;P&gt;I want to check for Windows hosts where the number of Context Switches/sec is higher than a calculated amount. That calculation needs to take into account the number of processors on the system.&lt;/P&gt;&lt;P&gt;To get the number of processors, I found that I can run the following search:&lt;BR /&gt;index="perfmon" sourcetype="Perfmon:CPU" instance!="_Total" | stats dc(instance) AS NumProcessors by host&lt;/P&gt;&lt;P&gt;To get the number of Context Switches/sec, it's as easy as:&lt;BR /&gt;index="perfmon" sourcetype="Perfmon:System" counter="Context Switches/sec"&lt;/P&gt;&lt;P&gt;And I want to limit the events in the context switches query to where Value = 5000 * NumProcessors. I thought a subsearch might be the way, but I can't seem to get that to work. This is something like what I want, but it doesn't work because the subsearch usage is wrong.&lt;/P&gt;&lt;P&gt;index="perfmon" sourcetype="Perfmon:System" counter="Context Switches/sec"&lt;BR /&gt;| stats avg(Value) AS avg_cs by host&lt;BR /&gt;| where avg_cs &amp;gt; (5000 * [search index="perfmon" host=$host$ sourcetype="Perfmon:CPU" instance!="_Total" | stats dc(instance) AS NumProcessors by host])&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 17:36:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552082#M156676</guid>
      <dc:creator>jheiselman</dc:creator>
      <dc:date>2021-05-18T17:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate where criteria with value from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552084#M156677</link>
      <description>&lt;P&gt;Got it to work for me.&lt;/P&gt;&lt;P&gt;index="perfmon" sourcetype="Perfmon:System" counter="Context Switches/sec"&lt;BR /&gt;| stats avg(Value) AS avg_cs by host&lt;BR /&gt;| sort host&lt;BR /&gt;| appendcols&lt;BR /&gt;&amp;nbsp; [ search index="perfmon" sourcetype="Perfmon:CPU" instance!="_Total"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; | stats dc(instance) AS NumProcessors by host&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; | sort host]&lt;BR /&gt;| eval threshold=(5000*NumProcessors)&lt;BR /&gt;| where avg_cs&amp;gt;=threshold&lt;BR /&gt;| rename avg_cs AS "Context Switches/sec"&lt;BR /&gt;| fields host, "Context Switches/sec", threshold&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 18:16:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552084#M156677</guid>
      <dc:creator>jheiselman</dc:creator>
      <dc:date>2021-05-18T18:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate where criteria with value from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552116#M156685</link>
      <description>&lt;P&gt;When using appendcols, you need to be 100% certain that the number of rows in your outer search and the number of rows in the subsearch are the same, otherwise the columns will not necessarily line up with the correct, in your case, host.&lt;/P&gt;&lt;P&gt;It is sometimes better to use append, as below, which means less sorting and no issue with missing host data&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="perfmon" sourcetype="Perfmon:System" counter="Context Switches/sec"
| stats avg(Value) AS avg_cs by host
| append
  [ search index="perfmon" sourcetype="Perfmon:CPU" instance!="_Total"
    | stats dc(instance) AS NumProcessors by host 
    | eval threshold=(5000*NumProcessors) ]
| stats values(*) as * by host
| where !isnull(threshold) AND avg_cs&amp;gt;=threshold
| rename avg_cs AS "Context Switches/sec"
| fields host, "Context Switches/sec", threshold
| sort host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This basically creates data set 1 and data set 2, with the common host field.&lt;/P&gt;&lt;P&gt;The stats values(*) as * by host, collapses and joins the columns for each host. Where there is no threshold, if for example, the subsearch does not have data for the search, the isnull() check handles that case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 23:32:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552116#M156685</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-05-18T23:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate where criteria with value from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552236#M156719</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;When using appendcols, you need to be 100% certain that the number of rows in your outer search and the number of rows in the subsearch are the same, otherwise the columns will not necessarily line up with the correct, in your case, host.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Understood. Part of what I've excluded is a couple of lookups done to ensure that the host list is always the same and in the same order.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 16:00:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-where-criteria-with-value-from-a-subsearch/m-p/552236#M156719</guid>
      <dc:creator>jheiselman</dc:creator>
      <dc:date>2021-05-19T16:00:27Z</dc:date>
    </item>
  </channel>
</rss>

