![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) | |||||||||||||||
| Junior Member | Monitoring processor usage - thoughts Hi all, I wonder if you guys have any thoughts about the following. I set up a scheduled tasks that every minute polls for the processorload. The server is not very busy atm, but when this script runs from the scheduled task we get a small spike which in turns make the statistics unreliable. But this is not always the case, for instance if I start the scheduled task manually consecutive times, I don't get the same spikes in processor usage. (spike = appx 50%, when the gwmi poll gets done in ps via scheduled task) My questions are; When running a powershell script like this as a scheduled tasks, will a lot of cpu be consumed for starting up powershell? or maybe for initializing the database connections? will this scew my statistics? rockmoose Below is the script, (I enclose it in [php] tags, hopefully it will make it formatted...) This is how I call it from the scheduled task: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "D:\tasks\Monitor\processor.ps1"
| |||||||||||||||
| | #2 (permalink) |
| Junior Member | Just tested some more. If I execute the scheduled task manually by rightclicking and choosing "run", I get 0-10% processor load. The seconds after when the scheduled task is run according to schedule the processor load reports 30-60%. So I don't really know where all these cpu-cycles are consumed. The nt-scheduler? The powershell engine? .NET framework? Db-connections? ............................ Ok, when starting the script, taskmanager shows powershell using 15-20% cpu for a brief moment. Maybe the moment of the poll is slightly different when running the scheduled task manually contra scheduled.. ? This might not be an ideal use of ps, but on of my first attempts :-) ---- pretty lousy when coming to think of it ---- rockmoose |
| | #3 (permalink) |
| Guest | RE: Monitoring processor usage - thoughts Try running it from another machine. WMI can connect to a remote machine. Use the -computername parameter to specify the machine. That way the additional CPU usage of starting PowerShell won't impact your results -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty "rockmoose" wrote: > > Hi all, > > I wonder if you guys have any thoughts about the following. > > I set up a scheduled tasks that every minute polls for the > processorload. > The server is not very busy atm, but when this script runs from the > scheduled task we get a small spike which in turns make the statistics > unreliable. > > But this is not always the case, for instance if I start the scheduled > task manually consecutive times, I don't get the same spikes in > processor usage. > > (spike = appx 50%, when the gwmi poll gets done in ps via scheduled > task) > > > My questions are; > When running a powershell script like this as a scheduled tasks, > will a lot of cpu be consumed for starting up powershell? or maybe for > initializing the database connections? will this scew my statistics? > > rockmoose > > > Below is the script, (I enclose it in > PHP code: > -------------------- > tags, hopefully it will make it formatted...) > This is how I call it from the scheduled task: > C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "D:\tasks\Monitor\processor.ps1" > > > > PHP code: > -------------------- > # monitors processor usage > > $processor = Get-WmiObject -class Win32_Processor -Property DeviceID,LoadPercentage > for($i = 0; $i –lt $processor.Count; $i++) > { > #@($computer["Name"],$processor[$i].DeviceID,$processor[$i].LoadPercentage) > > $cn = new-object system.data.SqlClient.SqlConnection("Data Source=srvname;Integrated Security=SSPI;Initial Catalog=dbname"); > $cmd = new-object system.Data.Sqlclient.SqlCommand("monitor_performanceCounterValue_add", $cn); > > $cmd.CommandType = [System.Data.CommandType]"StoredProcedure" > $cmd.Parameters.AddWithValue("@object","Processor") | Out-Null > $cmd.Parameters.AddWithValue("@instance",$processor[$i].DeviceID) | Out-Null > $cmd.Parameters.AddWithValue("@counter","LoadPercentage") | Out-Null > $cmd.Parameters.AddWithValue("@computer","srvname") | Out-Null > $cmd.Parameters.AddWithValue("@value",[decimal]$processor[$i].LoadPercentage) | Out-Null > > $cn.Open() > $cmd.ExecuteNonQuery() | Out-Null > $cn.Close() > > } > -------------------- > > > -- > rockmoose > ------------------------------------------------------------------------ > rockmoose's Profile: http://vista64.net/forums/member.php?userid=1022 > View this thread: http://vista64.net/forums/showthread.php?t=30140 > > |
| | #4 (permalink) |
| Guest | RE: Monitoring processor usage - thoughts you can also use performancecounters for this (also remote) http://mow001.blogspot.com/2005/12/g...info-from.html Greetings /\/\o\/\/ "RichS" wrote: > Try running it from another machine. WMI can connect to a remote machine. > Use the -computername parameter to specify the machine. > > That way the additional CPU usage of starting PowerShell won't impact your > results > -- > Richard Siddaway > > Please note that all scripts are supplied "as is" and with no warranty > > > "rockmoose" wrote: > > > > > Hi all, > > > > I wonder if you guys have any thoughts about the following. > > > > I set up a scheduled tasks that every minute polls for the > > processorload. > > The server is not very busy atm, but when this script runs from the > > scheduled task we get a small spike which in turns make the statistics > > unreliable. > > > > But this is not always the case, for instance if I start the scheduled > > task manually consecutive times, I don't get the same spikes in > > processor usage. > > > > (spike = appx 50%, when the gwmi poll gets done in ps via scheduled > > task) > > > > > > My questions are; > > When running a powershell script like this as a scheduled tasks, > > will a lot of cpu be consumed for starting up powershell? or maybe for > > initializing the database connections? will this scew my statistics? > > > > rockmoose > > > > > > Below is the script, (I enclose it in > > PHP code: > > -------------------- > > tags, hopefully it will make it formatted...) > > This is how I call it from the scheduled task: > > C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "D:\tasks\Monitor\processor.ps1" > > > > > > > > PHP code: > > -------------------- > > # monitors processor usage > > > > $processor = Get-WmiObject -class Win32_Processor -Property DeviceID,LoadPercentage > > for($i = 0; $i –lt $processor.Count; $i++) > > { > > #@($computer["Name"],$processor[$i].DeviceID,$processor[$i].LoadPercentage) > > > > $cn = new-object system.data.SqlClient.SqlConnection("Data Source=srvname;Integrated Security=SSPI;Initial Catalog=dbname"); > > $cmd = new-object system.Data.Sqlclient.SqlCommand("monitor_performanceCounterValue_add", $cn); > > > > $cmd.CommandType = [System.Data.CommandType]"StoredProcedure" > > $cmd.Parameters.AddWithValue("@object","Processor") | Out-Null > > $cmd.Parameters.AddWithValue("@instance",$processor[$i].DeviceID) | Out-Null > > $cmd.Parameters.AddWithValue("@counter","LoadPercentage") | Out-Null > > $cmd.Parameters.AddWithValue("@computer","srvname") | Out-Null > > $cmd.Parameters.AddWithValue("@value",[decimal]$processor[$i].LoadPercentage) | Out-Null > > > > $cn.Open() > > $cmd.ExecuteNonQuery() | Out-Null > > $cn.Close() > > > > } > > -------------------- > > > > > > -- > > rockmoose > > ------------------------------------------------------------------------ > > rockmoose's Profile: http://vista64.net/forums/member.php?userid=1022 > > View this thread: http://vista64.net/forums/showthread.php?t=30140 > > > > |
| | #5 (permalink) |
| Guest | RE: Monitoring processor usage - thoughts For that kind of monitoring interval, I'd think you want to write the script as loop with a one minute sleep interval, then start one instance and leave it running. "rockmoose" wrote: > > Hi all, > > I wonder if you guys have any thoughts about the following. > > I set up a scheduled tasks that every minute polls for the > processorload. > The server is not very busy atm, but when this script runs from the > scheduled task we get a small spike which in turns make the statistics > unreliable. > > But this is not always the case, for instance if I start the scheduled > task manually consecutive times, I don't get the same spikes in > processor usage. > > (spike = appx 50%, when the gwmi poll gets done in ps via scheduled > task) > > > My questions are; > When running a powershell script like this as a scheduled tasks, > will a lot of cpu be consumed for starting up powershell? or maybe for > initializing the database connections? will this scew my statistics? > > rockmoose > > > Below is the script, (I enclose it in > PHP code: > -------------------- > tags, hopefully it will make it formatted...) > This is how I call it from the scheduled task: > C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "D:\tasks\Monitor\processor.ps1" > > > > PHP code: > -------------------- > # monitors processor usage > > $processor = Get-WmiObject -class Win32_Processor -Property DeviceID,LoadPercentage > for($i = 0; $i –lt $processor.Count; $i++) > { > #@($computer["Name"],$processor[$i].DeviceID,$processor[$i].LoadPercentage) > > $cn = new-object system.data.SqlClient.SqlConnection("Data Source=srvname;Integrated Security=SSPI;Initial Catalog=dbname"); > $cmd = new-object system.Data.Sqlclient.SqlCommand("monitor_performanceCounterValue_add", $cn); > > $cmd.CommandType = [System.Data.CommandType]"StoredProcedure" > $cmd.Parameters.AddWithValue("@object","Processor") | Out-Null > $cmd.Parameters.AddWithValue("@instance",$processor[$i].DeviceID) | Out-Null > $cmd.Parameters.AddWithValue("@counter","LoadPercentage") | Out-Null > $cmd.Parameters.AddWithValue("@computer","srvname") | Out-Null > $cmd.Parameters.AddWithValue("@value",[decimal]$processor[$i].LoadPercentage) | Out-Null > > $cn.Open() > $cmd.ExecuteNonQuery() | Out-Null > $cn.Close() > > } > -------------------- > > > -- > rockmoose > ------------------------------------------------------------------------ > rockmoose's Profile: http://vista64.net/forums/member.php?userid=1022 > View this thread: http://vista64.net/forums/showthread.php?t=30140 > > |
| | #6 (permalink) |
| Junior Member | > "Try running it from another machine. WMI can connect to a remote machine. Use the -computername parameter to specify the machine." That was my original plan, unfortunately I had som problems with some of the counters, so I opted to run the ps scripts locally and send the results to the db. (http://www.vista64.net/forums/showthread.php?t=29567) >"you can also use performancecounters for this (also remote)" Thank you, is there any difference between the two approaches? Win32_Processor or Win32_PerfFormattedData_PerfProc_Process >"For that kind of monitoring interval, I'd think you want to write the script as loop with a one minute sleep interval, then start one instance and leave it running." Ok, I will try that, just need to figure out how to write the sleep & loop function. But would Thread.Sleep work in a scripting environment? I'll try it, but does anybody know? or does ps have an inbuilt sleep function? rockmoose |
| | #7 (permalink) | |||||||||||||||
| Junior Member | Here is the revised script. This is working ok now.
Win32_Processor or Win32_PerfFormattedData_PerfProc_Process? Another thing, If the process is terminated, is there any way of having something like a "finally" block to close the database connection? rockmoose | |||||||||||||||
| | #8 (permalink) |
| Guest | Re: Monitoring processor usage - thoughts On Fri, 22 Dec 2006 12:37:41 +0000, rockmoose <rockmoose.2j7x6p@no-mx.vista64.net> wrote: > > Hi all, > > I wonder if you guys have any thoughts about the following. > > I set up a scheduled tasks that every minute polls for the > processorload. > The server is not very busy atm, but when this script runs from the > scheduled task we get a small spike which in turns make the statistics > unreliable. The CLR forms a (heavy) bit of a load when a .Net application starts. It seems to be even worse when no other .Net apps are running at the moment, although that difference could simply be a matter of files being in disk cache or not. If I wanted to monitor performance of the local machine, I would write a small (compiled) app that can be kept running. I would definitely *not* use the task scheduler to start an application for each sample. It's like launching the task manager, and looking only at the first CPU use sample of the graph: always 100%. |
| | #9 (permalink) |
| Guest | Re: Monitoring processor usage - thoughts Powershell has a start-sleep cmdlet. "rockmoose" wrote: > > -> "Try running it from another machine. WMI can connect to a remote > machine. > Use the -computername parameter to specify the machine.--" > > -That was my original plan, unfortunately I had som problems with some > of the counters, so I opted to run the ps scripts locally and send the > results to the db. > (http://www.vista64.net/forums/showthread.php?t=29567) > > - > >"you can also use performancecounters for this (also remote)" > > -Thank you, is there any difference between the two approaches? > Win32_Processor or Win32_PerfFormattedData_PerfProc_Process > > ->"For that kind of monitoring interval, I'd think you want to write > the script > as loop with a one minute sleep interval, then start one instance and > leave > it running." > > -Ok, I will try that, just need to figure out how to write the sleep & > loop function. > But would Thread.Sleep work in a scripting environment? > I'll try it, but does anybody know? or does ps have an inbuilt sleep > function? > > > rockmoose > > > -- > rockmoose > ------------------------------------------------------------------------ > rockmoose's Profile: http://vista64.net/forums/member.php?userid=1022 > View this thread: http://vista64.net/forums/showthread.php?t=30140 > > |
| | #10 (permalink) |
| Junior Member | " If I wanted to monitor performance of the local machine, I would write a small (compiled) app that can be kept running. I would definitely *not* use the task scheduler to start an application for each sample." Yes, agreed. but one of the strong points about scripting is that you don't need to compile and deploy much. And the first attempt was, umh, pretty mediocre. The loop approach in the script seems to work very well. " Powershell has a start-sleep cmdlet." Found it thanks! rockmoose |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Probably a simple question about disk/processor usage | lovelyshadeofgreen | PowerShell | 1 | 1 Week Ago 05:14 AM |
| Need some thoughts on what to do! | MrBiggz | Sound & Audio | 4 | 12-27-2007 03:37 PM |
| Thoughts So Far | Verger | Vista installation & setup | 3 | 08-19-2007 06:04 AM |
| DPCs causing 100% processor usage at random times | sebbelcher | Vista performance & maintenance | 1 | 07-13-2007 10:02 AM |
| 100% Processor usage - svchost.exe | Tim | Vista performance & maintenance | 3 | 07-07-2006 11:13 AM |