Yes, I know we can use the uptime command to find out the system load average. The uptime command displays the current time, the length of time the system has been up, the number of users, and the load average of the system over the last 1, 5, and 15 minutes. However, if you try to use the uptime command in script, you know how difficult it is to get correct load average. As the time since the last, reboot moves from minutes, to hours, and an even day after system rebooted. Just type the uptime command:
$ uptime
Sample outputs:
1:09:01 up 29 min, 1 user, load average: 0.00, 0.00, 0.00
OR
$ uptime
Sample outputs:
2:13AM up 34 days, 16:15, 36 users, load averages: 1.56, 1.89, 2.06
Traditionally, UNIX administrators used sed and other shell command in scripting to get correct value of load average. Here is my own modified hack to save the time
$ uptime | awk -F'load averages:' '{ print $2 }'
OR better use the following code:
$ uptime | awk -F'[a-z]:' '{ print $2}'
Output taken from my OS X desktop:
1.24 1.34 1.35
Output taken from my Ubuntu Linux server:
0.00, 0.01, 0.05
Output taken from my RHEL based server:
0.24, 0.27, 0.21
Output taken from my FreeBSD based server:
0.71, 0.71, 0.58
Please note that command works on all variant of UNIX operating systems.
See also
- See chksysload.bash script to notify admin user if script load crossed certain limit and if so send them an email alert.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 10 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
cat /proc/loadavg
Can use “getloadavg” function of “stdlib.h”.
(FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=getloadavg)
Anybody care to explain what these load average figures mean? Is there a unit or is there anything scalely comparable to them? For example, I have:
21:39:33 up 10:45, 5 users, load average: 9.86, 9.68, 10.64
What do 9.86, 9.68 and 10.64 mean here?
It means, load averages of CPU in last 1, 5 and 15 mins…
Actually This will work fine, cause there will be different output based on u r last reboot.
# Find the correct field to extract based on how long
# the system has been up, or since the last reboot.
if $(uptime | grep day | grep min >/dev/null)
then
FIELD=11
elif $(uptime | grep day | grep hrs >/dev/null)
then
FIELD=11
elif $(uptime | grep day >/dev/null)
then
FIELD=10
elif $(uptime | grep min >/dev/null)
then
FIELD=9
else
FIELD=8
fi
Actually it DOES work. I found that the ‘s’ in ‘averges’ should not be there. Otherwise it works like a charm!
Yes, U r right Szy, it works and there should not be ‘s’ in average… It worked fine on AIX. thanks
stefan. his example clearly shows that that just doesn’t work all the time. specifically when uptime is
This information is wrong. The correct command would be:
uptime | awk '{print $10 " " $11 " " $12}'
The above does not work on Solaris 8.
This information is wrong.
You can’t just pipe to awk and assume that the 10th field will be the load average.
Because the time field could be 1 or 2 items. “47 days” or “15:45”. Because it’s not consistent you can’t assume the 10th field will be load average.
# uptime
18:17:27 up 47 days, 47 min, 2 users, load average: 0.09, 0.23, 0.42
# uptime | awk ‘{print $10}’
average:
See.