<?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: Do i have to use a join in mstats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574605#M200245</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1st - thanks for the answer - I think I am very close - but I just cant get to the final push.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to use append=t prestats=t so I don't have to use a join.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However when I introduce a field "threshold" in the "BY" clause that is in one tstat and not the other and try to use this in the stats...I lose data. In this case, R stops coming in.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas? I think I am close, but I am just missing something&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-11 15_39_33-Untitled - Paint.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16819iEE460D3CF9524176/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2021-11-11 15_39_33-Untitled - Paint.png" alt="2021-11-11 15_39_33-Untitled - Paint.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-11 15_38_26-Untitled - Paint.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16821i859E586DB97E880C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2021-11-11 15_38_26-Untitled - Paint.png" alt="2021-11-11 15_38_26-Untitled - Paint.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mstats append=t prestats=t  min("mx.replica.status") WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY "service.name" replica.name service.type 
| mstats append=t prestats=t min("mx.process.cpu.utilization")  WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY "service.name" replica.name service.type threshold

| stats min("mx.replica.status") as R min("mx.process.cpu.utilization") as C by _time "service.name" replica.name service.type threshold&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Nov 2021 15:47:02 GMT</pubDate>
    <dc:creator>robertlynch2020</dc:creator>
    <dc:date>2021-11-11T15:47:02Z</dc:date>
    <item>
      <title>Do i have to use a join in mstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574438#M200180</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/103"&gt;@sideview&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Nick&lt;/P&gt;&lt;P&gt;I am using a join with mstat, but i am hoping that i dont have to.&lt;/P&gt;&lt;P&gt;However, i cant crack it - any help would be amazing.&lt;/P&gt;&lt;P&gt;Below is the current SPL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mstats min("mx.process.cpu.utilization") as cpuPerc WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY pid  service.type  service.name replica.name
| rename "service.name" as service_name 
| rename "replica.name" as replica_name 
| rename "service.type" as service_type 
| eval Process_Name=((service_name . " # ") . replica_name) 
| sort 0 - _time 
| dedup _time pid 
| join type=left Process_Name _time 
    [| mstats min("mx.replica.status") as Replica WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY "service.name" replica.name service.type 
    | rename "service.name" as service_name 
    | rename "replica.name" as replica_name 
    | eval Process_Name=((service_name . " # ") . replica_name) 
    | table Process_Name, Replica, "service.type", _time 
    | sort 0 - _time 
    | dedup _time Process_Name] 
| table _time Process_Name Replica cpuPerc service_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tored to make it one mstats but that will not work as in this case&amp;nbsp;min("mx.replica.status") as Replica as no pid so Splunk gives me back blank for this field. SO do i have to use a JOIN?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mstats mstats min("mx.replica.status") as Replica min("mx.process.cpu.utilization") as cpuPerc WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY pid  service.type  service.name replica.name
| rename "service.name" as service_name 
| rename "replica.name" as replica_name 
| rename "service.type" as service_type 
| eval Process_Name=((service_name . " # ") . replica_name) 
| sort 0 - _time 
| dedup _time pid 
| table _time Process_Name Replica cpuPerc service_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 16:16:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574438#M200180</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2021-11-10T16:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Do i have to use a join in mstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574456#M200189</link>
      <description>&lt;P&gt;I think the join might be avoidable.&lt;/P&gt;&lt;P&gt;In general though the rule of thumb is that when one or both sides are generating commands like this, the normal bag of tricks isn't there - ie making a disjunction and normalizing/cajoling with eval, making stats do the work etc.&lt;/P&gt;&lt;P&gt;but!!&amp;nbsp;&amp;nbsp; the silver lining here is that with both tstats and mstats there is a way to avoid the limits of join and append commands, in that they both have an append=true (at least if prestats=t)&lt;/P&gt;&lt;P&gt;so, lose the join, append=t the second mstats, some TBD conditional eval to make the names work out, and then &amp;lt;handwave&amp;gt; eval and stats and friends to make it work out "like a left join"&lt;/P&gt;&lt;P&gt;i realize there's a bit of handwaving there and someone else might have an intuitive leap to be able to post a full answer without data to play in.&lt;/P&gt;&lt;P&gt;Also, I know that with tstats there are some confusing pitfalls around prestats=t having to do with field names not being what you expect, and I wonder (but dont really know) whether mstats prestat=t has the same ones.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 17:42:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574456#M200189</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2021-11-10T17:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Do i have to use a join in mstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574605#M200245</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1st - thanks for the answer - I think I am very close - but I just cant get to the final push.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to use append=t prestats=t so I don't have to use a join.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However when I introduce a field "threshold" in the "BY" clause that is in one tstat and not the other and try to use this in the stats...I lose data. In this case, R stops coming in.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas? I think I am close, but I am just missing something&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-11 15_39_33-Untitled - Paint.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16819iEE460D3CF9524176/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2021-11-11 15_39_33-Untitled - Paint.png" alt="2021-11-11 15_39_33-Untitled - Paint.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-11 15_38_26-Untitled - Paint.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/16821i859E586DB97E880C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2021-11-11 15_38_26-Untitled - Paint.png" alt="2021-11-11 15_38_26-Untitled - Paint.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mstats append=t prestats=t  min("mx.replica.status") WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY "service.name" replica.name service.type 
| mstats append=t prestats=t min("mx.process.cpu.utilization")  WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY "service.name" replica.name service.type threshold

| stats min("mx.replica.status") as R min("mx.process.cpu.utilization") as C by _time "service.name" replica.name service.type threshold&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 15:47:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574605#M200245</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2021-11-11T15:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do i have to use a join in mstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574899#M200337</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;In the end this was very tricky, but the below code is what I used.&lt;/P&gt;&lt;P&gt;Please note this was for the full example.&amp;nbsp; I would suggest reading this answer as well as there are lots of hints and tricks that have to be applied to get it to work - To be honest its a lot of work - but it does work.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/What-exactly-are-the-rules-requirements-for-using-quot-tstats/m-p/319801" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/What-exactly-are-the-rules-requirements-for-using-quot-tstats/m-p/319801&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mstats append=t prestats=t min("mx.replica.status") min("mx.process.resources.status") WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY service.name replica.name service.type 
| eval threshold = "" 
| eval pid="" 
| eval cmd="" 
| eval host.name="" 
| eval component.name="" 
| mstats append=t prestats=t min("mx.process.threads") min("mx.process.memory.usage") min("mx.process.file_descriptors") min("mx.process.cpu.utilization") min("mx.process.up.time") avg("mx.process.creation.time") WHERE "index"="metrics_test" AND mx.env=http://mx20267vm:15000 span=10s BY pid cmd service.type host.name service.name replica.name component.name threshold 
| rename service.name as service_name 
| rename replica.name as replica_name 
| rename "service.type" as service_type 
| stats min("mx.process.resources.status") as Resources min("mx.process.up.time") as upTime avg("mx.process.creation.time") as creationTime min("mx.replica.status") as Replica min("mx.process.threads") as nbOfThreads min("mx.process.memory.usage") as memoryCons min("mx.process.file_descriptors") as nbOfOpenFiles min("mx.process.cpu.utilization") as cpuPerc by _time pid cmd service_type host.name service_name replica_name component.name threshold 
| eval T_NbOfThreads=if(isnull(nbOfThreads),"",threshold) 
| eval T_MemoryCons=if(isnull(memoryCons),"",threshold) 
| eval T_NbOfOpenFiles=if(isnull(nbOfOpenFiles),"",threshold) 
| eval T_CpuPerc=if(isnull(cpuPerc),"",threshold) 
| eval Process_Name=((service_name . " # ") . replica_name) 
| sort 0 - _time Process_Name 
| streamstats last(Replica) as Replica 
| streamstats last(Resources) as Resources 
| where cmd !="" 
| stats values(Resources) as Resources values(Replica) as Replica values(cpuPerc) as cpuPerc values(nbOfThreads) as nbOfThreads values(memoryCons) as memoryCons values(nbOfOpenFiles) as nbOfOpenFiles values(upTime) as upTime values(creationTime) as creationTime values(T_NbOfOpenFiles) as T_NbOfOpenFiles values(T_MemoryCons) as T_MemoryCons values(T_CpuPerc) as T_CpuPerc values(T_NbOfThreads) as T_NbOfThreads by _time pid cmd Process_Name service_type host.name service_name replica_name component.name 
| eval Status=(Resources * Replica) 
| eval Status=if((Status == 4),2,if((Status == 0),0,1)) 
| eval Replica=case((Process_Name == "xmlserver # xmlserver"),"2",(Process_Name == "zookeeper # zookeeper"),"2",(Process_Name == "fileserver # fileserver"),"2",true(),Replica) 
| dedup _time pid 
| sort 0 - _time pid 
| table _time Resources Replica pid cmd service_type host.name service_name replica_name component.name cpuPerc nbOfThreads memoryCons nbOfOpenFiles upTime creationTime&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 09:55:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Do-i-have-to-use-a-join-in-mstats/m-p/574899#M200337</guid>
      <dc:creator>robertlynch2020</dc:creator>
      <dc:date>2021-11-15T09:55:21Z</dc:date>
    </item>
  </channel>
</rss>

