Site icon UnixArena

Solaris – Memory & Swap Usage Script

solaris memory usage

How to find the exact memory and swap usage of Solaris server?  Solaris uses the memory as /tmp and swap will be calculated along with physical memory. We need to use the right commands to figure out the utilization of both. “top” is one if the best monitoring tool but it’s not inbuilt in Solaris 10.  I have created the small script to do this monitoring purpose.

Following Commands used in the script:

 

How do you to find total physical memory & total swap space in Solaris? How do you find free physical memory &  free swap space on the system?

 

Script:

#!/usr/bin/bash
# Solaris SPARC/X86 Memory Statistics  report script version 0.12
echo "=========================================="
echo "It works on Solaris 10 and ealier versions"
echo "Thank you for using UnixArena script"
echo "=========================================="
swap -l |awk '{ print $4 }'|grep -v blocks > temp.swapl
swap -l |awk '{ print $5}'|grep -v free > free.swap1
MEM=$(echo `echo '::memstat' | mdb -k |tail -1|awk '{ print $3 }'` "*" "1024"|bc)
SWP=$(echo $(tr -s '\n' '+' < temp.swapl)0 | bc)
TSWP=$(echo "$SWP" "/" "2" |bc)
TOTALVS=$(echo "$MEM" "+" "$TSWP" |bc)
echo "Total Physical Memory = $(echo "$MEM" "/" "1024" "/" "1024" |bc) GB"
echo "Total Swap Space = $(echo "$TSWP" "/" "1024" "/" "1024" |bc) GB"
echo "Total Virtual storage space(Physical + Swap) = $(echo "$TOTALVS" "/" "1024" "/" "1024" |bc) GB"
FREEVS=$(echo `vmstat 1 2 |tail -1|awk ' { print $4 } '` "+" `vmstat 1 2 |tail -1|awk ' { print $5 } '` |bc)
echo "Free Physical Memory = $(echo "scale=2;`vmstat 1 2 |tail -1|awk ' { print $5 } '` "/" "1024" "/" "1024" "|bc) GB"
echo "Free Swap = $(echo "scale=2;`awk '{total += $NF} END { print total }' free.swap1` "/" "2" "/" "1024" "/" "1024" "|bc) GB"
echo "Free Virtual storage space(Free Physical + Free Swap) = $(echo "$FREEVS" "/" "1024" "/" "1024" |bc) GB"
FREEVSP=$(echo "scale=2;$FREEVS*100/$TOTALVS" |bc)
echo "Free Virtual storage Percentage = $FREEVSP % "
FREEVSPR=$(echo $FREEVSP|cut -c 1-2)
rm temp.swapl
if [[ "$FREEVSPR" -gt 15 ]]
then
echo "System is running with enough virtual storage space(Free virtual storage space $FREEVSP %)"
exit 0
echo "========"
echo "GOOD BYE"
echo "========"
else
echo " UnixArena:`uname -n` : os: The percentage of available storage space is low ($FREEVSP percent)"
exit 1
echo "========"
echo "GOOD BYE"
echo "========"
fi
#Created by Lingeswaran Rangasamy (Email: lingeshwaran.rangasamy@gmail.com)(Website: www.unixarena.com)

 

Sample output of the script:

Total Physical Memory = 251 GB
Total Swap Space = 295 GB
Total Virtual storage space(Physical + Swap) = 546 GB
Free Physical Memory = 87.48 GB
Free Swap = 273.95 GB
Free Virtual storage space(Free Physical + Free Swap) = 361 GB
Free Virtual storage Percentage = 66.11 %
System is running with enough virtual storage space(Free virtual storage space 66.11 %)

 

Verifying the script output with other system commands:

# vmstat 1 5
 kthr      memory            page            disk          faults      cpu
 r b w   swap  free  re  mf pi po fr de sr m1 m1 m1 m2   in   sy   cs us sy id
 0 0 0 336864920 125991448 1363 4799 823 68 67 0 2 23 21 21 0 13576 97161 16001 10 3 87
 0 0 0 287271208 91721144 365 4181 0 0 0 0 0 0 0  0  0 13604 59918 19709 8 4 88
 0 0 0 287271864 91721328 967 4212 0 8 8 0 0 2 2  2  0 13183 56024 18985 8 4 88
 0 0 0 287268216 91721320 383 4104 60 0 0 0 0 0 0 0  0 10641 40352 13485 8 3 89

 

Verifying using top output:

# /usr/local/bin/top
last pid: 23154;  load averages:  7.63,  9.27,  9.92      16:30:04
1467 processes:1460 sleeping, 2 zombie, 5 on cpu
CPU states: 90.3% idle,  5.4% user,  4.3% kernel,  0.0% iowait,  0.0% swap
Memory: 256G real, 87G free, 230G swap in use, 273G swap free

 

Hope this script have saved your time to find memory statistics on Solaris servers.I have tested this script in Solaris 10 SPARC & X86 servers.

Exit mobile version