<?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: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338968#M100521</link>
    <description>&lt;P&gt;Well, that is good to know...  I have a search like this in a dashboard, modified to try for an alert every 3 minutes (cron expression). I made the values super low to ensure it hits constantly, as a test, but this is not even triggering even though the values are low enough.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;host="HOST1" sourcetype="Perfmon:CPU Load" object=Processor counter="% Processor Time" instance=_Total |bucket _time span=2m| eval PercentProcessorTime=Value | append [search host="HOST1" source="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use" | eval PercentCommittedBytesInUse=Value] | stats avg(PercentProcessorTime) as "CPU",avg(PercentCommittedBytesInUse) as "Memory" | table _time CPU Memory |where CPU &amp;gt; 5 AND Memory &amp;gt; 25&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 21:38:48 GMT</pubDate>
    <dc:creator>DPZ_Luke</dc:creator>
    <dc:date>2017-03-07T21:38:48Z</dc:date>
    <item>
      <title>How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338961#M100514</link>
      <description>&lt;P&gt;I want an alert thrown whenever a two minute interval shows the average CPU and average Memory usage both exceeding 70%.&lt;BR /&gt;
But I am stymied in that the Append command does not work for real time and can't figure out an alternative.&lt;BR /&gt;
I've tried many variations of the following, to no avail.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[host="HOST1" sourcetype="Perfmon:CPU Load" counter="% Processor Time" | bucket _time span=2m | where Value &amp;gt; 70] AND [host="HOST1" source="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use" |bucket _time span=2m |where Value &amp;gt; 70]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This seems like something that should be very common.&lt;BR /&gt;
Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 14:38:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338961#M100514</guid>
      <dc:creator>DPZ_Luke</dc:creator>
      <dc:date>2017-03-07T14:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338962#M100515</link>
      <description>&lt;P&gt;[Updated - Included Stats command, changed span=1m] &lt;/P&gt;

&lt;P&gt;You can try something like the following. I have used timechart but you can use stats. Also depending upon whether you want to use the query for Dashboard or Alert, you can set the time range for the search and might not need explicit span=1m or  bucket _time span=1m&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="HOST1" (sourcetype="Perfmon:CPU Load" object="Processor" counter="% Processor Time") OR (sourcetype="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use")
| search Value&amp;gt;70
| eval metrics=object." - ".Value
| timechart span=1m count as eventcount values(metrics) as metrics
| search eventcount &amp;gt;1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Stats Command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="Perfmon:*" (object="Processor*" counter="% Processor Time") OR (object=Memory counter="% Committed Bytes In Use")
| search Value&amp;gt;70 
| eval metrics=object." - ".Value
| bin span=1m _time 
| stats count as eventcount values(metrics) as metrics by _time
| search eventcount&amp;gt;1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 17:26:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338962#M100515</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-03-07T17:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338963#M100516</link>
      <description>&lt;P&gt;This is for an alert. I'm a newb so not sure when to use timechart or stats.&lt;BR /&gt;
The above solution is closer but it fails because I record CPU every 1 minute and the span=2m is picking up the CPU value at, for example, 12:00:00 and 12:01:00 so it always hits even though that is two CPU hits and not one CPU/one Memory.&lt;BR /&gt;
I've tried changing span to 1m and it works but fires off alerts every 5 seconds, for the same value, so that is no good.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 18:58:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338963#M100516</guid>
      <dc:creator>DPZ_Luke</dc:creator>
      <dc:date>2017-03-07T18:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338964#M100517</link>
      <description>&lt;P&gt;My assumption is that you will always have at least one record for each host in every 10-second period. The code can be adjusted to longer pulse-time if needed.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  your base search providing _time, host, CPU% (where 70=79%) and memory% (where 70=79%).   
| table _time host pctCPU pctMemory
| bucket _time span=10s
| stats avg(pctCPU) as pctCPU1, max(pctCPU) as maxCPU1, 
    avg(pctMemory) as pctMemory1 max(pctMemory), as maxMemory1 by host _time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above code takes whatever records are returned by your base search, and chunks them up to a 10-second pulse, showing the average and max stats across that pulse.&lt;/P&gt;

&lt;P&gt;Now you have one record per host every 10 seconds.  You can proceed here two different ways.  You can either use streamstats with a rolling two minute window, or you can set fixed two-minute windows. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Fixed Period Method&lt;/STRONG&gt; ...Now we bucket it up to the 2 minute mark (but use eventstats to retain the individual 10s-level records for inspection later...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| bucket _time as time2 span=2m
| eventstats avg(pctCPU1) as pctCPU2, max(maxCPU1) as maxCPU2, 
    avg(pctMemory1) as pctMemory2, max(maxMemory1) as maxMemory2  by host time2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Rolling Window Method&lt;/STRONG&gt;...or we use streamstats with a 2-minute rolling window  (which is 12 of the ten-second chunks) ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats avg(pctCPU1) as pctCPU2, max(maxCPU1) as maxCPU2, 
    avg(pctMemory1) as pctMemory2, max(maxMemory1) as maxMemory2  by host window=12
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;.. and in either of the above cases, the following selects the records to alert on...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where  pctCPU2&amp;gt;=70 AND pctMemory2&amp;gt;=70
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 18:59:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338964#M100517</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-07T18:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338965#M100518</link>
      <description>&lt;P&gt;DalJeanis,&lt;BR /&gt;
I could see your technique working, except with my example, how do you specify what value is pctCPU and which is pctMemory?&lt;/P&gt;

&lt;P&gt;This is my base search.&lt;BR /&gt;
host="HOST1" (sourcetype="Perfmon:CPU Load" object="Processor" counter="% Processor Time") OR (sourcetype="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use")&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:47:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338965#M100518</guid>
      <dc:creator>DPZ_Luke</dc:creator>
      <dc:date>2017-03-07T19:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338966#M100519</link>
      <description>&lt;P&gt;@DPZ_Luke, first of all sorry search Value should have been greater than 70. I have corrected the same in my answer. I have also added query with stats command. Hoping you run the query for last 1 minute with span=1m.&lt;/P&gt;

&lt;P&gt;Based on your scenario you should go for streamstats (@DalJeanis has suggested one). How soon do you want your search queries to run (or what is the schedule for your alert)?&lt;BR /&gt;
What is the period you want to look back to identify threshold breach for both Memory and CPU?&lt;/P&gt;

&lt;P&gt;For example you run the search: &lt;BR /&gt;
1) every 2 minute for past 2 minute or &lt;BR /&gt;
2) every 2 minutes for past 3 minutes or&lt;BR /&gt;
3) every minute for past 1 minute or&lt;BR /&gt;
4) every minute for past 2 minutes&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:38:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338966#M100519</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-03-07T20:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338967#M100520</link>
      <description>&lt;P&gt;The problem is that you are using &lt;CODE&gt;real-time&lt;/CODE&gt;; don't.  It is WAY more trouble that it is worth.  Instead run a search over the last X minutes and then schedule it for every X/2 minutes.  Try to make X as big as you can stomach.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:39:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338967#M100520</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-07T20:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338968#M100521</link>
      <description>&lt;P&gt;Well, that is good to know...  I have a search like this in a dashboard, modified to try for an alert every 3 minutes (cron expression). I made the values super low to ensure it hits constantly, as a test, but this is not even triggering even though the values are low enough.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;host="HOST1" sourcetype="Perfmon:CPU Load" object=Processor counter="% Processor Time" instance=_Total |bucket _time span=2m| eval PercentProcessorTime=Value | append [search host="HOST1" source="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use" | eval PercentCommittedBytesInUse=Value] | stats avg(PercentProcessorTime) as "CPU",avg(PercentCommittedBytesInUse) as "Memory" | table _time CPU Memory |where CPU &amp;gt; 5 AND Memory &amp;gt; 25&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338968#M100521</guid>
      <dc:creator>DPZ_Luke</dc:creator>
      <dc:date>2017-03-07T21:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338969#M100522</link>
      <description>&lt;P&gt;Thanks all, between all the help, I got it working. Final Query:&lt;BR /&gt;
* host="HOST1" sourcetype="Perfmon:CPU Load" object=Processor counter="% Processor Time" instance=_Total |bucket _time span=2m | eval PercentProcessorTime=Value | append [search host="HOST1" source="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use" |bucket _time span=2m | eval PercentCommittedBytesInUse=Value] | streamstats avg(PercentProcessorTime) as "CPU",avg(PercentCommittedBytesInUse) as "Memory" by host window=2 | table _time CPU Memory | where CPU &amp;gt; 70 AND Memory &amp;gt; 70&lt;/P&gt;

&lt;P&gt;with a scheduled alert running on cron expression */2 * * * * (every 2 minutes)&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 15:25:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338969#M100522</guid>
      <dc:creator>DPZ_Luke</dc:creator>
      <dc:date>2017-03-08T15:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338970#M100523</link>
      <description>&lt;P&gt;First do this and find the name of the value field that has the CPU percent... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="HOST1" (sourcetype="Perfmon:CPU Load" object="Processor" counter="% Processor Time") | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then do this and find the name of the value field that has the memory percent... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="HOST1" (sourcetype="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use") | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...then this becomes your base search...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="HOST1" (sourcetype="Perfmon:CPU Load" object="Processor" counter="% Processor Time") 
OR (sourcetype="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use")
| eval pctCPU=if(sourcetype="Perfmon:CPU Load",    ....Memory field name...  , null())
| eval pctMemory=if(sourcetype="Perfmon:Memory",   .....CPU field name.....  , null())
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Mar 2017 16:08:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338970#M100523</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-08T16:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338971#M100524</link>
      <description>&lt;P&gt;Don't use streamstats in that scenario, just use stats.  That "window=2" will just get you the last two records, whatever they are and what order they come in.  They are not going to get you an actual average across 2 minutes, just across every pair of records (by host) that flow through the stream.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="HOST1" (sourcetype="Perfmon:CPU Load" object="Processor" counter="% Processor Time") 
 OR (sourcetype="Perfmon:Memory" collection=Memory object=Memory counter="% Committed Bytes In Use")
 | eval PercentProcessorTime=if(sourcetype="Perfmon:CPU Load",Value,null())
 | eval PercentCommittedBytesInUse=if(sourcetype="Perfmon:Memory",Value,null())
 | bucket _time span=2m
 | stats avg(PercentProcessorTime) as CPU, avg(PercentCommittedBytesInUse) as Memory by host _time
 | where CPU&amp;gt;70 AND Memory&amp;gt;70
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;update March 24- even worse, it turns out that &lt;CODE&gt;| streamstats avg(...) by host window=2&lt;/CODE&gt; will calculate the average of however many of the last two records had the same host value as the current record, ie sometimes one, sometimes two.  You can only use that combination if you have &lt;CODE&gt;sort&lt;/CODE&gt;ed or &lt;CODE&gt;stat&lt;/CODE&gt;ed immediately prior to ensure that the records are in host and time order, or with the &lt;CODE&gt;global=true&lt;/CODE&gt; parameter set so that splunk will apply window=2 to the &lt;CODE&gt;by host&lt;/CODE&gt; parameter rather than just to ehte current stream.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 16:20:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338971#M100524</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-08T16:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my real time alert to trigger when average CPU and memory usage exceeds 70% in a 2 minute span?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338972#M100525</link>
      <description>&lt;P&gt;Thanks for the update. I've made those changes.&lt;BR /&gt;
However, it seems to be doing something unexpected. It is generating alerts for events that occurred yesterday that met the criteria. I kinda expected it to only trigger if new events are flagged.&lt;BR /&gt;
It makes me wonder, is it rerunning the search for the entirety of log history at every cron interval and then triggering on each instance?&lt;BR /&gt;
How do I configure it to only recent/new events?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 21:58:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-real-time-alert-to-trigger-when-average-CPU-and/m-p/338972#M100525</guid>
      <dc:creator>DPZ_Luke</dc:creator>
      <dc:date>2017-03-08T21:58:21Z</dc:date>
    </item>
  </channel>
</rss>

