

You may want to start by looking into top or htop result to see the processes overview.Īs you can see below, it gives an excellent idea about what all processes are utilizing. But if you don’t have one or looking for a command-based solution, then here you go. There are many monitoring software which does this out of the box. However, imagine a shared server where multiple services are running, and you need to find which one is eating all the resources. If the server host just one process, then it’s easy to find out when the process consumes all the resources. If retrieves the memory usage either in percent (without the percent sign) or in bytes by returning an array with free and overall memory of your system.Know how much an individual process or system-wide consume CPU or memory.Īs a sysadmin, you often have to deal with an incident where the application is slow or unresponsive due to high CPU/memory/network utilization. So if you need the overall memory usage, following function might be helpful. But intuitively, many people expect to get the memory usage of the system, based on the name of the function. Memory_get_usage() is used to retrieve the memory allocated to PHP only (or your running script). $load = 100 - ( $statData2 * 100 / $cpuTime) Įcho " CPU load not estimateable (maybe too old Windows or missing rights at Linux or Windows)" Invert percentage to get CPU time, not idle time $cpuTime = $statData2 + $statData2 + $statData2 + $statData2 the percentage of idle time (which is part of the 4 values!) Sum up the 4 values for User, Nice, System and Idle and calculate Collect 2 samples - each with 1 second period $cmd = " wmic cpu get loadpercentage $cmd, $output) Returns server load in percent (just number, without percent sign) It will return a decimal value as percentage of current CPU load or NULL if something went wrong (e. Function to get current CPU load as percentage value under Windows and Linux.
