Hey ALL,
I there anyway my CPU load alert gives more info like which process eating CPU stuff like that? did anyone implement this solution.
Here is the top 10 Script on Windows for CPU. In 4.2 it returns just one message with the list of top 10 processes. It was created to give a quick look so tier 1 knows who owns the processes causing problems without taking the time to login to the server. It can pretty easily be modified to only return 1 result, or to return 10 results if you are on 4.2 - Just keep in mind that 4.2 doesn't handle dynamic results very well, so instead of using something like:Statistic.variable1
You'll need to statically set the returns and have the Message field handle any dynamic info.
Option ExplicitDim objWMIService, objRefresherDim strComputer, strListDim colProcesses, sliceProcesses()Dim objProcess, tempProcessDim i, j, iPos, iMax, listLenstrComputer = WScript.Arguments.Item(0)Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2")Set objRefresher = CreateObject("WbemScripting.SWbemRefresher")set colProcesses = objRefresher.AddEnum (objWMIService, _ "Win32_PerfFormattedData_PerfProc_Process").objectSetobjRefresher.RefreshWScript.Sleep(1000)objRefresher.RefreshRedim Preserve sliceProcesses(0)i = 0'strip Idle, Total, and 0 valuesFor Each objProcess In colProcesses If ((objProcess.PercentProcessorTime > 0) _ And (Not objProcess.name = "Idle") _ And (Not objProcess.Name = "_Total")) Then Redim Preserve sliceProcesses(i) Set sliceProcesses(i) = objProcess i = i+1 End IfNext'Selection Sort, didn't feel like fighting with it to get a sliceFor iPos = 0 To UBound(sliceProcesses) iMax = iPos For i = iPos+1 To UBound(sliceProcesses) If CInt(sliceProcesses(i).PercentProcessorTime) > _ CInt(sliceProcesses(iMax).PercentProcessorTime) Then iMax = i End If Next If (Not iMax = iPos) Then Set tempProcess = sliceProcesses(iPos) Set sliceProcesses(iPos) = sliceProcesses(iMax) Set sliceProcesses(iMax) = tempProcess End IfNextIf UBound(sliceProcesses) > 10 Then listLen = 10 Else listLen = UBound(sliceProcesses)'Sad excuse for Array SliceFor i = 0 To listLen strList = strList & vbNewLine & sliceProcesses(i).Name & _ " " & sliceProcesses(i).PercentProcessorTimeNextWScript.Echo "Message: " & strListWScript.Echo "Statistic: 0"
And the same script for *nix systems. Same caveats as above apply to this one as well.
#!/usr/bin/perlmy @results = `ps -eo ppid,comm,pcpu | sort -r -k 3 | head -n 11`;push(my @output, "\n" . shift(@results));push(@output, sort {($b =~ m/(\d+\.\d$)/)[0] <=> ($a =~ m/(\d+\.\d$)/)[0]} @results);my $list = "";$list .= $_ for (@output);print "Message: $list\n";print "Statistic: 0";
I'd like to reiterate though that the value of these for gathering historical data is minimal. I'm pretty sure that alterego has mentioned before that they are working on allowing dynamic multi-value scripts in future versions of APM. Right now though I would just rely on these as informational scripts to cut down on time spent logging in to the servers.
This is not currently possible today in APM to show which processes are consuming the most CPU, but this a feature we've included in the next release. You can learn more about what's in store for the next release in my blog post, as well as signup to participate in the beta.
You can simulate this with a script. You'd need to pull the CPU information for all processes, sort the results, then return the process name/ID in the Message field.
It won't be all that useful for historical data, but can be a useful tool for quickly checking the biggest offender(s) without needing to connect to VPN, RDP, etc. to actually look at the server.I don't know that you'd be able to tie this to NPM's CPU Load alert though.If you are interested I have scripts for 4.2 that returns Top 10 processes on both *nix and Windows. They could be modified to return just one result for prior versions. Like I said previously though, these are really just informational monitors and the historical data isn't likely to be very useful for trending.
@bobross - That would be great! Please share your script with me. Thanks a lot.
@aLTeReGo - thanks for reply. Looking forward...
Great!!!!!!!!
Do you know how to implement it with Advance Alert so whenever my CPU load goes above 90% it will run script and send output along with email alerts..
Here's a super secret sneak peek into one of our new out-of-the-box alerts included in the forthcoming SAM 5.0 release. SAM 5.0 went into release candidate phase this week. I'll be posting a blog post early next week inviting existing APM customers to participate in the RC. This week we're slow rolling invitations out to customers who participated in the original beta.
Wow, that would be great for our environment. What is SAM?
SAM is the new name for APM. Server & Applications Monitor