Test free mem in console on windows - windows

It's pretty obvious on every platform to see the amount of free mem, but I need to get the value in a batch script.
good old mem command is limited to 64MB
What should I use?

You can use performance counters. There are a few ways to query performance counters from the command line. Probably the simplest way is with the typeperf command. The following example displays one sample (-sc 1) of the “Available Mbytes” counter from the “Memory” object on the “kennypc” computer.
typeperf "\\kennypc\memory\available mbytes" -sc 1
There are a variety of performance counters to choose from to get just the results you need. The Performance Monitor snap-in (perfmon.msc) can be used to browse through the available performance counters.

WMI can help.
wmic os get FreePhysicalMemory

Related

How to fetch list of running processes on a system and sort them by various parameters

I use htop to view information about the processes currently running in my osx machine, also to sort them by CPU, memory usage, etc.
Is there any way to fetch the output of htop programatically in Ruby?. Also I would like to be able to use the API to sort the processes using various parameters like CPU, memory usage, etc.
I can do IO.popen('ps -a') and parse the output, but want to know if there is a better way than directly parsing the output of a system command run programmatically.
Check out sys-proctable:
require 'sys/proctable'
Sys::ProcTable.ps
To sort by starttime:
Sys::ProcTable.ps.sort_by(&:starttime)

Set an application's resource limits (CPU usage)

It's a little strange I know,
but I want to limit a program (for example the winrar app) resource usage.
The reason:
I have an old laptop, with overheating problem, so if I want to do a calculate intensive task (compress a >10GB folder), my laptop overheats and turns off.
The question:
Is it possible to limit an application's resource/CPU usage? For example, can I set somehow, that winrar can only use my CPU's 50%?
I use windows 8.1,
but answer for other OS is welcome.
See Are there solutions that can limit the CPU usage of a process? for general answer.
WinRAR itself has the command line switch -ri, see in help of WinRAR the page with title:
Switch -RI<p>[:<s>] - set priority and sleep time
For example using a command line like
WinRAR.exe a -ri1:100 Backup.rar *
results in compressing all files in current working directory with default settings using lowest task priority and with 100 ms sleep time between each read or write operation.

Network Usage of Process Using Powershell

I want to calculate the bytes sent and recieved by a particular process .I want to use powershell for that.
Something which I can do using Resource Monitor->Network Activity.
How can i do that using get-counter?
There is a really good Scripting Guy article on using the Get-Counter cmdlet here:
Scripting Guy - Get-Counter
The trick will be finding the counter that you need, and I don't think you can get the granularity you're after as these are the same counters that PerfMon uses. It's more focused around the whole Network Interface than it is around the individual processes using the interface. With that said, if it's the only thing using the given interface it should do the trick nicely.
Have a look at the Network Interface options available for a start:
(get-counter -list "Network Interface").paths
You can't, it seems. I'm absolutely unable to find the counters the performance monitor is reading from, though other people may chime in. There may be some other way than get-counter too, but that is what you specifically requested.
Looking through the counters, the closest thing you will find is the "IO Read Bytes/sec" and "IO Write Bytes/sec" counters on the process object.
The problem with those is that they count more than just network activity. The description in perfmon says:
"This counter counts all I/O activity generated by the process to
include file, network and device I/Os."
That being said, if you know that the process you want to monitor only or mainly writes to the network connection, this may be better than not measuring anything at all.
You'd go about it like this (I'll use Chrome as an example since it is conveniently running and using data right now):
get-counter "\Process(chrome*)\IO Read Bytes/sec"
This will just give you a one-time reading. If you want to keep reading you can add the continous switch.
The PerformanceCounterSampleSet object that is returned is not exactly pretty to work with, but you can find the actual reading in $obj.countersamples.cookedvalue.
The list will be fairly long (if you browse like me). Chrome is running in many separate processes, so we'll do a bit of math to get them all added up, and presented in KB.
Final result:
get-counter "\Process(chrome*)\IO Read Bytes/sec" -Continuous | foreach {
[math]::round((($_.countersamples.cookedvalue | measure -sum).sum / 1KB), 2)
}
Running this will just continously output a reading of how many KB/s Chrome is using.

windows system command to find out cpu/ram usage for the machine+specific app/webapp

I wish to determine the CPU/ RAM being used currently in a Windows based virtual machine or Server- for the machine itself, as well as for a specific app/web-app running on that machine.
I have with me the details of the app/web app that is being executed on that Windows machine.
The app will typically be a web app, and it can be in one of the following languages--> php/java/ruby/python/.net/node.js/perl.
Ideally I would prefer if a single command could be used to determine the pid for a app/web app that uses any of the above languages, however if a single command could be used (for all/each of the above languages) that would be ideal for me.
Another question--> how do I do something like the above, when the machine is a Windows machine? I.e.
(1) What command to use in Windows OS based machine to determine process ID
(2) What command to use to use in Windows OS based machine to determine CPU/RAM used by a app/web app running in Windows based Machine.
(3) Command to determine overall usage of CPU/RAM by the system (not any specific process).
Look at tasklist to find the process ID of a process.
Look at WMIC for CPU usage for the system and specific apps.
Combined with find or findstr, should give you all the info you need.
CPU and RAM Usage of an application or process can be fetched from a Windows OS using WMI Commands in Perl/Python/Java/VB Script
We need to execute 2 WMI Select Queries and apply CPU% utilization formula
1. To retrieve the total number of logical process
select NumberOfLogicalProcessors from Win32_ComputerSystem
2. To retrieve the values of PercentProcessorTime, TimeStamp_Sys100NS ( CPU utilization formula has be applied get the actual utilization percentage)and WorkingSetPrivate ( RAM ) minimum of 2 times with a sleep interval of 1 second
select * from Win32_PerfRawData_PerfProc_Process where IDProcess=1234
3. Apply CPU% utilization formula
CPU%= ((p2-p1)/(t2-t1)*100)/NumberOfLogicalProcessors
p2 indicated PercentProcessorTime retrieved for the second time, and p1 indicateds the PercentProcessorTime retrieved for the first time, t2 and t1 is for TimeStamp_Sys100NS.
A sample Perl code for this can be found in the link http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/
This logic applies for all programming language which supports WMI queries

System Resource Monitor/Graph

I'm looking for an app that does about the same thing at the Performance tab on Task Manager, but on a per-process basis and with more plotted values. At a minimum, I would like to be able to plot CPU and memory usage but it would be nice if it could plot:
Network usage
File system IO (per drive/share sub headings would be nice)
Open file stream count
LSOF like stuff
All the other stats that the Process tab can give you
... anything else ...
Windows comes with perfmon which is pretty much exactly what you want. It has infinity different counters with different categories - also individual apps can register their own counters.
I worked with Norm at FS Walker Hughes, he made this and published it on CodeProject
What you exacly need is this => processstudio
Both have full source code available.
Enjoy!
Just use NAPI.

Resources