Checking uptime and load average with uptime
- Version
- unversioned
- Review
- Draft
Summary#
uptime prints the current time, how long the system has run, the number of logged-in users and the load averages for the last 1, 5 and 15 minutes.
Syntax#
uptime
uptime -p
cat /proc/loadavg
nproc
uptime -p prints only the running time in words. nproc prints how many processing units are available to the current process, which gives the load numbers their scale.
Example#
(
set -eu
LC_ALL=C uptime | grep -c 'load average:'
awk '{ print "fields in /proc/loadavg:", NF }' /proc/loadavg
test "$(nproc)" -ge 1
echo 'at least one processing unit is available'
)
Expected output#
The load values differ on every run, so the script counts the matching line and fields.
1
fields in /proc/loadavg: 5
at least one processing unit is available
Common mistakes#
Load average is not a CPU percentage. On Linux it counts tasks that are running or waiting to run and tasks in uninterruptible sleep, often waiting for disk. Compare it with the number of processing units, and check what the tasks wait for before blaming the CPU. A falling 1-minute value next to a high 15-minute value means the busy period is ending.
Version applicability#
This entry describes uptime from procps-ng on Linux and nproc from GNU Coreutils. BusyBox and macOS format the line differently.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0