How to calculate CPU and memory utilization on solaris box

I am trying to write shell script to calculate memory and cpu utilization on solaris box.

For CPU utilization, I tried below command but I want to append date, time and host name in same command but on solaris I am unable to append

sar -u 1 | awk '{print $5}' | tail -1 | awk '{sub=100 - $1} {print "Total CPU Utilization = " sub "%"}'

For memory utilization I tried below commands

TOP="/opt/sfw/bin/top"

$TOP | grep Memory | awk '{print $2" "$4}'| sed -e 's/M//g' | awk '{sub=$1 - $2} {print "Total Memory Utilization = " (sub/$1)* 100"%"}'

I want to remove TOP variable and in the single command I want to return total memory utilization count, because I am unable to access top dir/file, so wanted to implement different approach.

can any one suggest changes for above two scripts ?

Thanks,


Here's some good documentation here, https://docs.oracle.com/cd/E53394_01/html/E54798/gmaem.html

It's been years since I used Solaris. But I think I would assign the hostname and date to variables, then use echo or printf to output them.