• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

UnixArena

  • Home
  • kubernetes
  • DevOps
    • Terraform
    • Jenkins
    • Docker
    • Openshift
      • OKD
    • Ansible engine
    • Ansible Tower
      • AWX
    • Puppet
  • Cloud
    • Azure
    • AWS
    • Openstack
    • Docker
  • VMware
    • vCloud Director
    • VMware-Guests
    • Vcenter Appliance 5.5
    • vC OPS
    • VMware SDDC
    • VMware vSphere 5.x
      • vSphere Network
      • vSphere DS
      • vShield Suite
    • VMware vSphere 6.0
    • VSAN
    • VMware Free Tools
  • Backup
    • Vembu BDR
    • Veeam
    • Nakivo
    • Azure Backup
    • Altaro VMBackup
    • Spinbackup
  • Tutorials
    • Openstack Tutorial
    • Openstack Beginner’s Guide
    • VXVM-Training
    • ZFS-Tutorials
    • NetApp cDot
    • LVM
    • Cisco UCS
    • LDOM
    • Oracle VM for x86
  • Linux
    • How to Articles
    • Q&A
    • Networking
    • RHEL7
  • DevOps Instructor-led Training
  • Contact

Solaris – Memory & Swap Usage Script

May 4, 2013 By Cloud_Devops 4 Comments

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:

  • echo ‘::memstat’ | mdb -k  –  To find physical memory
  • swap -l  –  To find total swap space
  • vmstat 1 2 – To find current free memory & free swap

 

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.

Filed Under: Solaris 10, Unix admin scripts, Unix Monitoring tools Tagged With: Memory, script, Solaris, swap

Reader Interactions

Comments

  1. Tamer says

    December 30, 2019 at 11:55 pm

    Any chance to have one for solaris 11 please?

    Reply
  2. Mayank says

    April 10, 2017 at 11:34 pm

    Can you please check the google document page? Unable to download the script.

    Reply
  3. Richard Unwin says

    January 11, 2017 at 4:49 pm

    Great script. Thankyou for making it availble. Saved me many hours of work.

    Reply
  4. Mayank Shah says

    May 6, 2016 at 10:10 am

    last pid: 7491; load avg: 1.20, 1.14, 1.12; up 834+13:29:32 05:35:25
    154 processes: 146 sleeping, 3 zombie, 3 stopped, 2 on cpu
    CPU states: 96.3% idle, 3.4% user, 0.3% kernel, 0.0% iowait, 0.0% swap
    Memory: 8184M phys mem, 1045M free mem, 2052M total swap, 1808M free swap

    So in this case,total swap space is 2052mb out of which 1808mb is free…it it correct??

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow UnixArena

  • Facebook
  • LinkedIn
  • Twitter

Copyright © 2025 · UnixArena ·

Go to mobile version