gleam/os_mon/cpu
A CPU Load and CPU Utilization Supervisor Process
Description
cpu_sup
is a process which supervises the CPU load and CPU utilization.
It is part of the OS_Mon application, see os_mon(6)
. Available for Unix,
although CPU utilization values util
are only available for Solaris,
Linux and FreeBSD.
The load values are proportional to how long time a runnable Unix process
has to spend in the run queue before it is scheduled. Accordingly, higher
values mean more system load. The returned value divided by 256 produces
the figure displayed by rup
and top
. What is displayed as 2.00 in
rup
, is displayed as load up to the second mark in xload.
For example, rup
displays a load of 128 as 0.50, and 512 as 2.00.
If the user wants to view load values as percentage of machine capacity, then this way of measuring presents a problem, because the load values are not restricted to a fixed interval. In this case, the following simple mathematical transformation can produce the load value as a percentage:
Percent_load = 100 * (1 - d / (d + load))
d
determines which load value should be associated with which
percentage.
Choosing d
= 50 means that 128 is 60% load, 256 is 80%, 512 is 90%, and
so on.
Another way of measuring system load is to divide the number of busy CPU cycles by the total number of CPU cycles. This produces values in the 0-100 range immediately. However, this method hides the fact that a machine can be more or less saturated. CPU utilization is therefore a better name than system load for this measure.
A server which receives just enough requests to never become idle will score a CPU utilization of 100%. If the server receives 50% more requests, it will still score 100%. When the system load is calculated with the percentage formula shown previously, the load will increase from 80% to 87%.
The avg1/0, avg5/0, and avg15/0 functions can be used for retrieving
system load values, and the util
function can be used for retrieving CPU
utilization values.
When run on Linux, cpu_sup
assumes that the /proc
file system is
present and accessible by cpu_sup
. If it is not, cpu_sup
will
terminate.
Types
Statitics about CPU usage
pub type CpuUtilization {
CpuUtilization(
soft_irq: Float,
hard_irq: Float,
kernel: Float,
nice_user: Float,
user: Float,
steal: Float,
idle: Float,
wait: Float,
)
}
Constructors
-
CpuUtilization( soft_irq: Float, hard_irq: Float, kernel: Float, nice_user: Float, user: Float, steal: Float, idle: Float, wait: Float, )
pub type CpuUtilizationDetailed {
CpuUtilizationDetailed(ids: List(Int), details: CpuUtilization)
}
Constructors
-
CpuUtilizationDetailed(ids: List(Int), details: CpuUtilization)
pub type CpuUtilizationTotal {
CpuUtilizationTotal(active: Float, idle: Float)
}
Constructors
-
CpuUtilizationTotal(active: Float, idle: Float)
Functions
pub external fn average() -> Float
Returns CPU utilization since the last call to average
by the calling
process.
Note:
The returned value of the first call to average
by a process will on most
systems be the CPU utilization since system boot, but this is not
guaranteed and the value should therefore be regarded as garbage. This also
applies to the first call after a restart of cpu_sup
.
The CPU utilization is defined as the sum of the percentage shares of the CPU cycles spent in all busy processor states in average on all CPUs.
Returns 0 if cpu_sup
is not available.
pub external fn average_1() -> Int
Returns the average system load in the last minute, as described above. 0 represents no load, 256 represents the load reported as 1.00 by rup.
Returns 0 if cpu_sup
is not available.
pub external fn average_15() -> Int
Returns the average system load in the last fifteen minutes, as described above. 0 represents no load, 256 represents the load reported as 1.00 by rup.
Returns 0 if cpu_sup
is not available.
pub external fn average_5() -> Int
Returns the average system load in the last minute, as described above. 0 represents no load, 256 represents the load reported as 1.00 by rup.
Returns 0 if cpu_sup
is not available.
pub external fn nprocs() -> Int
Returns the number of UNIX processes running on this machine. This is a crude way of measuring the system load, but it may be of interest in some cases.
Returns 0 if cpu_sup
is not available.
pub fn utilization() -> CpuUtilizationTotal
pub fn utilization_detailed() -> CpuUtilizationDetailed
pub fn utilization_detailed_per_cpu() -> List(CpuUtilization)
Returns CPU utilization since the last call to utilization
by the calling
process.
Note:
The returned value of the first call to utilization
by a process will on
most systems be the CPU utilization since system boot, but this is not
guaranteed and the value should therefore be regarded as garbage. This also
applies to the first call after a restart of cpu_sup
.
Throws an exception if cpu_sup
is not available.
pub fn utilization_per_cpu() -> List(CpuUtilizationTotal)