How to check CPU and RAM load?

  • Автор темы Автор темы Aronax
  • Дата начала Дата начала

Aronax

Client
Регистрация
29.01.2015
Сообщения
214
Реакции
64
Баллы
28
Hi all,

In one of my templates, I need to check the CPU and RAM load.

If CPU and / or RAM load are higher than 80-90%, I need this template to stop opening new threads (using .bat files). If these parameters are below 80-90% load, I need this template to continue opening new threads.

Thanks
 
Thanks a lot. It works like a charm
 
If anybody needs it, I also found this code for getting the CPU load. You need to add System.Management in GAC references and using "System.Management;" (without "") on the "Using directives" tab in "Using directives tab and shared code" interface. Then, this code will work:

C#:
Развернуть Свернуть Копировать
var searcher = new System.Management.ManagementObjectSearcher ("select * from Win32_PerfFormattedData_PerfOS_Processor");

var cpuUsage = searcher.Get()
    .Cast<System.Management.ManagementObject>()
    .Select(mo => new
    {
        Name = mo["Name"],
        Usage = mo["PercentProcessorTime"]
    }
    ).ToArray();

return (ulong)cpuUsage[0].Usage;

Works great for me
 
Последнее редактирование:
Nice solution!
However, there is Resource monitor feature for that,
which does not allow to run new threads if CPU and Memory usage is too high.
Resource monitor.png
 
  • Спасибо
Реакции: Aronax

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)