I would like to get the memory utilization in sun solaris system in % percentage format.
vmstat 1 1 | tail -1 | awk 'a=`/usr/sbin/prtconf|fgrep Memory|awk '{print $3*1024}'{ print 100-($5/$a)*100}'
Getting below error:
awk: syntax error near line 1
awk: bailing out near line 1
Also, please suggest if any alternative possible for this query?
Using Solaris awk
(which would not have the -v
switch or allow setting variables), and using your original query to start with, you can do:
Percentage of free memory:
a=$(/usr/sbin/prtconf | /usr/bin/awk '/Memory/ {print $3*1024}'); vmstat 1 1 | tail -1 | awk "{print (\$5/$a)*100}"
Percentage of used memory:
a=$(/usr/sbin/prtconf | /usr/bin/awk '/Memory/ {print $3*1024}'); vmstat 1 1 | tail -1 | awk "{print 100-(\$5/$a)*100}"
Assign the variable in shell first, then execute the vmstat
query using shell variable substitution. This requires using the double quotes in the awk
and making sure to escape the awk
variable. You also do not need to use fgrep
and awk
together, awk
can do both.
Tested on my Opensolaris I have available, so YMMV.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments