I am working on the project that requires monitoring of% of CPU in use. It's supposed to be on both Mac and Windows, so I'm using Mono and XMarine.
I'm using to get this code (this is an exam but the counter is the same):
var cpuCounter = new displayConverter {className = " Processor ", CounterName ="% Processor Time ", InstanceName =" _Total "}; CpuCounter.NextValue (); Thread Sleep (1000); For (var i = 0; i <50; i ++) {console. WriteLine (cpuCounter.NextValue ()); Thread Sleep (1000); }
On a PC, it works by what the Task Manager shows.
I have tried to googling and do not seem to be doing anything.
Thoughts?
We had a similar problem. The way we used to solve it, he was writing a script. I will share the code in script. And the way we told it to mono, call it
the script (call it and save it to / library / application support / exclusive app).
#! / Bin / bash ps x -o pcpu, com | Mono Code - var psi = New ProcessStart Infos ("/ bin / sh", "\" / library / application support / unique / GetCPU.sh \ "") {RedirectStandardOutput = true, UseShellExecute = false}; Process P = Process Start (psi); String Outstring = p.StandardOutput.ReadToEnd (); P.WaitForExit (); OutString = outString.Substring (0, 5).
The CPU percentage to be used by the unique App in Outstation
If you want CPU percent for the whole machine getCPU.sh for the following code Change -
#! / Bin / bash ps x -o pcpu | Tail-n + 2 | Awk '{s + = $ 1} END {print s}' '
No comments:
Post a Comment