1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>cpu_sup</title>
32
<module>cpu_sup</module>
33
<modulesummary>A CPU Load and CPU Utilization Supervisor Process</modulesummary>
35
<p><c>cpu_sup</c> is a process which supervises the CPU load
36
and CPU utilization. It is part of the OS_Mon application, see
37
<seealso marker="os_mon">os_mon(6)</seealso>. Available for Unix,
38
although CPU utilization values (<c>util/0,1</c>) are only
39
available for Solaris and Linux.</p>
40
<p>The load values are proportional to how long time a runnable
41
Unix process has to spend in the run queue before it is scheduled.
42
Accordingly, higher values mean more system load. The returned
43
value divided by 256 produces the figure displayed by <c>rup</c>
44
and <c>top</c>. What is displayed as 2.00 in <c>rup</c>, is
45
displayed as load up to the second mark in <c>xload</c>.</p>
46
<p>For example, <c>rup</c> displays a load of 128 as 0.50, and
48
<p>If the user wants to view load values as percentage of machine
49
capacity, then this way of measuring presents a problem, because
50
the load values are not restricted to a fixed interval. In this
51
case, the following simple mathematical transformation can
52
produce the load value as a percentage:</p>
54
PercentLoad = 100 * (1 - D/(D + Load))
56
<p><c>D</c> determines which load value should be associated with
57
which percentage. Choosing <c>D</c> = 50 means that 128 is 60%
58
load, 256 is 80%, 512 is 90%, and so on.</p>
59
<p>Another way of measuring system load is to divide the number of
60
busy CPU cycles by the total number of CPU cycles. This produces
61
values in the 0-100 range immediately. However, this method hides
62
the fact that a machine can be more or less saturated. CPU
63
utilization is therefore a better name than system load for this
65
<p>A server which receives just enough requests to never become
66
idle will score a CPU utilization of 100%. If the server receives
67
50% more requests, it will still scores 100%. When the system load
68
is calculated with the percentage formula shown previously,
69
the load will increase from 80% to 87%.</p>
70
<p>The <c>avg1/0</c>, <c>avg5/0</c>, and <c>avg15/0</c> functions
71
can be used for retrieving system load values, and
72
the <c>util/0</c> and <c>util/1</c> functions can be used for
73
retrieving CPU utilization values.</p>
74
<p>When run on Linux, <c>cpu_sup</c> assumes that the <c>/proc</c>
75
file system is present and accessible by <c>cpu_sup</c>. If it is
76
not, <c>cpu_sup</c> will terminate.</p>
80
<name>nprocs() -> UnixProcesses | {error, Reason}</name>
81
<fsummary>Get the number of UNIX processes running on this host</fsummary>
83
<v>UnixProcesses = int()</v>
84
<v>Reason = term()</v>
87
<p>Returns the number of UNIX processes running on this machine.
88
This is a crude way of measuring the system load, but it may
89
be of interest in some cases.</p>
90
<p>Returns 0 if <c>cpu_sup</c> is not available.</p>
94
<name>avg1() -> SystemLoad | {error, Reason}</name>
95
<fsummary>Get the system load average for the last minute</fsummary>
97
<v>SystemLoad = int()</v>
98
<v>Reason = term()</v>
101
<p>Returns the average system load in the last minute, as
102
described above. 0 represents no load, 256 represents the load
103
reported as 1.00 by <c>rup</c>.</p>
104
<p>Returns 0 if <c>cpu_sup</c> is not available.</p>
108
<name>avg5() -> SystemLoad | {error, Reason}</name>
109
<fsummary>Get the system load average for the last five minutes</fsummary>
111
<v>SystemLoad = int()</v>
112
<v>Reason = term()</v>
115
<p>Returns the average system load in the last five minutes, as
116
described above. 0 represents no load, 256 represents the load
117
reported as 1.00 by <c>rup</c>.</p>
118
<p>Returns 0 if <c>cpu_sup</c> is not available.</p>
122
<name>avg15() -> SystemLoad | {error, Reason}</name>
123
<fsummary>Get the system load average for the last fifteen minutes</fsummary>
125
<v>SystemLoad = int()</v>
126
<v>Reason = term()</v>
129
<p>Returns the average system load in the last 15 minutes, as
130
described above. 0 represents no load, 256 represents the load
131
reported as 1.00 by <c>rup</c>.</p>
132
<p>Returns 0 if <c>cpu_sup</c> is not available.</p>
136
<name>util() -> CpuUtil | {error, Reason}</name>
137
<fsummary>Get the CPU utilization</fsummary>
139
<v>CpuUtil = float()</v>
140
<v>Reason = term()</v>
143
<p>Returns CPU utilization since the last call to
144
<c>util/0</c> or <c>util/1</c> by the calling process.</p>
146
<p>The returned value of the first call to <c>util/0</c> or
147
<c>util/1</c> by a process will on most systems be the CPU
148
utilization since system boot, but this is not guaranteed
149
and the value should therefore be regarded as garbage. This
150
also applies to the first call after a restart of
153
<p>The CPU utilization is defined as the sum of the percentage
154
shares of the CPU cycles spent in all busy processor states
155
(see <c>util/1</c> below) in average on all CPUs.</p>
156
<p>Returns 0 if <c>cpu_sup</c> is not available.</p>
160
<name>util(Opts) -> UtilSpec | {error, Reason}</name>
161
<fsummary>Get the CPU utilization</fsummary>
163
<v>Opts = [detailed | per_cpu]</v>
164
<v>UtilSpec = UtilDesc | [UtilDesc]</v>
165
<v> UtilDesc = {Cpus, Busy, NonBusy, Misc}</v>
166
<v> Cpus = all | int() | [int()]()</v>
167
<v> Busy = NonBusy = {State, Share} | Share</v>
168
<v> State = user | nice_user | kernel</v>
169
<v> | wait | idle | atom()</v>
170
<v> Share = float()</v>
171
<v> Misc = []</v>
172
<v>Reason = term()</v>
175
<p>Returns CPU utilization since the last call to
176
<c>util/0</c> or <c>util/1</c> by the calling process, in
177
more detail than <c>util/0</c>.</p>
179
<p>The returned value of the first call to <c>util/0</c> or
180
<c>util/1</c> by a process will on most systems be the CPU
181
utilization since system boot, but this is not guaranteed
182
and the value should therefore be regarded as garbage. This
183
also applies to the first call after a restart of
186
<p>Currently recognized options:</p>
188
<tag><c>detailed</c></tag>
190
<p>The returned <c>UtilDesc</c>(s) will be even more
193
<tag><c>per_cpu</c></tag>
195
<p>Each CPU will be specified separately (assuming this
196
information can be retrieved from the operating system),
197
that is, a list with one <c>UtilDesc</c> per CPU will be
201
<p>Description of <c>UtilDesc = {Cpus, Busy, NonBusy, Misc}</c>:</p>
203
<tag><c>Cpus</c></tag>
205
<p>If the <c>detailed</c> and/or <c>per_cpu</c> option is
206
given, this is the CPU number, or a list of the CPU
208
<p>If not, this is the atom <c>all</c> which implies that
209
the <c>UtilDesc</c> contains information about all CPUs.</p>
211
<tag><c>Busy</c></tag>
213
<p>If the <c>detailed</c> option is given, this is a list
214
of <c>{State, Share}</c> tuples, where each tuple
215
contains information about a processor state that has
216
been identified as a busy processor state (see below).
217
The atom <c>State</c> is the name of the state, and
218
the float <c>Share</c> represents the percentage share of
219
the CPU cycles spent in this state since the last call to
220
<c>util/0</c> or <c>util/1</c>.</p>
221
<p>If not, this is the sum of the percentage shares of
222
the CPU cycles spent in all states identified as busy.</p>
223
<p>If the <c>per_cpu</c> is not given, the value(s)
224
presented are the average of all CPUs.</p>
226
<tag><c>NonBusy</c></tag>
228
<p>Similar to <c>Busy</c>, but for processor states that
229
have been identified as non-busy (see below).</p>
231
<tag><c>Misc</c></tag>
233
<p>Currently unused; reserved for future use.</p>
236
<p>Currently these processor states are identified as busy:</p>
238
<tag><c>user</c></tag>
240
<p>Executing code in user mode.</p>
242
<tag><c>nice_user</c></tag>
244
<p>Executing code in low priority (nice) user mode.
245
This state is currently only identified on Linux.</p>
247
<tag><c>kernel</c></tag>
249
<p>Executing code in kernel mode.</p>
252
<p>Currently these processor states are identified as non-busy:</p>
254
<tag><c>wait</c></tag>
256
<p>Waiting. This state is currently only identified on
259
<tag><c>idle</c></tag>
265
<p>Identified processor states may be different on different
266
operating systems and may change between different versions
267
of <c>cpu_sup</c> on the same operating system. The sum of
268
the percentage shares of the CPU cycles spent in all busy
269
and all non-busy processor states will always add up to
272
<p>Returns <c>{all,0,0,[]}</c> if <c>cpu_sup</c> is not
279
<title>See Also</title>
280
<p><seealso marker="os_mon">os_mon(3)</seealso></p>