How can I get the load average (and ONLY the load average) under Solaris?

2

I'm looking for the equivilent of cat /proc/loadavg under Linux or sysctl -n vm.loadavg under FreeBSD, but for Solaris. Solaris doesn't have either /proc/loadavg or sysctl.

I don't want the output of w or uptime, I want just the load averages. For example, I want:

0.53 0.39 0.80

Not:

13:30:44 up 51 days,  8:43,  2 users,  load average: 0.46, 0.39, 0.79

What terminal command will provide me with the 1, 5 and 10 minute load averages, and only the load averages, under Solaris?

Josh

Posted 2013-09-27T17:31:20.847

Reputation: 7 540

Answers

4

You can use awk to return only the last 3 fields from uptime:

uptime | awk '{print $(NF-2)" "$(NF-1)" "$(NF-0)}'

EDIT:

If you don't want the commas, you can use sed or tr to remove those:

uptime | awk '{print $(NF-2)" "$(NF-1)" "$(NF-0)}' | tr "," " "

uptime | awk '{print $(NF-2)" "$(NF-1)" "$(NF-0)}' | sed 's/,/ /g'

MaQleod

Posted 2013-09-27T17:31:20.847

Reputation: 12 560

1

Not quite the same format, but perhaps usable depending on what you want to do with it:

kstat -p 'unix:0:system_misc:avenrun*' | \
 awk '{printf "%s %.2f\n", $1, $2 / 256.0}'

The raw output from the kstat command (described in the kstat(1m) man page) is:

% kstat -p 'unix:0:system_misc:avenrun*'
unix:0:system_misc:avenrun_15min    42
unix:0:system_misc:avenrun_1min 17
unix:0:system_misc:avenrun_5min 25

Dividing the kstats by 256 provides the more familiar output.

alanc

Posted 2013-09-27T17:31:20.847

Reputation: 1 032

0

Apparently people have written their own loadavg

Keltari

Posted 2013-09-27T17:31:20.847

Reputation: 57 019

Ug, cronjob to run every minute, no thanks, there must be a better way! – Josh – 2013-09-27T20:12:39.157