Saturday, April 5, 2014

Check system information for Capacity Planning

Working for migration projects requires lots of mesurements about the current running environment that gives you right way for predictions, estimations about the newly build environment. Thinking BIG!!! as architect for the enterprise applications, I started digging details of the system information of every machine I mean, every box and I need to prepare a table that will give all the details about the machine. This will make easy for deciding various things for WebLogic domain and its related environment.

Script Objective: Capacity Measurements

The Capacity plan is critical where a Senior WebLogic Administrator or Infrastructure Architect need to be more smarter to make wise decisions on allocated infrastructure. If you know the mesurements you can tailor your environment to give best predicated application environment platform. I had seen there is a legacy(old) shell script which gives the required information for mesurements! But it is not really robust and effective to give the desired outputs. Some of the modern CPU architectures changed and the processor information given expanded way. I thought better to renovate it in myway.  What do you say? Yes! right hmmm, I on top of it :).

The script must give outcome following factors
1. CPU Architecture
2. Num CPUs and  CPU Speed
3. Operating System Release version
4. Memory Sized (RAM)
5. Server platform
6. Virtual IP Addresses

First understood each line it was written in the script, then I refined those lines as per my thoughts and tried to get the effective output. bugging my friends if I'm not able to get desired outputs.

One Generic factor is that, I want to make this script must executed on both Solaris and also on the Redhat Linux operating environment. And finally reached the Victory!

I wish you could execute and share your experiances on HP-UX, AIX platforms as well that could help many other scripting fans.
-->

Optimizing Script: Less pipes

Recently April 2014, While teaching UNIX & Linux Scripting for WebLogic Administrators revisited this script. The scripting can be more optimized when you use less pipes (|). The usage of two commands 'cat' and 'grep' on a text file here it is /proc/cpuinfo more costly why because the number of CPU cycle consumption is the factor, that why it is changed by Swetha here. The initial script used by Swetha on Ubuntu 12 got some of the info blank and non related outputs. Infact, Linux /proc/meminfo file provides you the RAM size in kb that is little incoveniance for us. Hence changed it to MB format also in this update.

Formatted output in bash script

This time (Oct 2014) we are working on transition project and need to know about the system, Mr. Nageswaraiah Nanisetty helped me to update this script again for formatting the output in a nice format using printf and C style format definition. Tested this script in the VM, test environment as well working excellent. That is really nice to copy into excel directly by colon as delimiter.
Hope you are excited to see what is that script ? Here it is...

#!/bin/bash
clear
PATH=$PATH:/usr/ccs/bin:/usr/share/lib:/sbin:/usr/sbin:/usr/local/bin:/bin
export PATH
echo "Today's date is `date`, this is week `date +.%V.`"

format="\n%20s : %-50s"
os=`uname`
case $os in
SunOS)
 nproc=`psrinfo |wc -l` ;
 prspeed=` psrinfo -v | grep -i Hz |awk '{print $6" " $7}'|uniq  `
 inet_addrs=`ifconfig -a |grep -i inet | awk '{print $2}' `
 mem=`prtconf |grep -i size`
 ;;
Linux)
 nproc=` grep -i processor /proc/cpuinfo |wc -l`
 prspeed=` grep -i model /proc/cpuinfo |grep -i hz |awk '{print $9 }'|uniq `
 inet_addrs=`ifconfig -a |grep -i inet | awk '{print $2}' |cut -d ":" -f 2`
mem=` grep -i MemTotal /proc/meminfo | awk '{print $2}' `
mem="$(($mem/1024))MB"
    VENDOR=`cat /proc/cpuinfo | grep 'vendor_id' | cut -d: -f2 | awk 'NR==1'`
    MODEL=`cat /proc/cpuinfo | grep 'model name' | cut -d: -f2 | awk 'NR==1'|sed 's/ //g'`
    MHZ=`more /proc/cpuinfo | grep 'cpu MHz' | cut -d: -f2 | awk 'NR==1'`
   FLAVOR=`lsb_release -i |awk '{print $3}'`


esac
hname=`hostname`
arch=`arch`
uname=`uname -r`
printf "$format"  "Processor Arch" $arch
printf "$format"  "Host name" $hname
printf "$format"  "Operating system" $os
printf "$format"  "Release" $uname
printf "$format"  "Number of CPU" $nproc
printf "$format"  "CPU speed" $prspeed
printf "$format"  "RAM Size" $mem
printf "$format" "CPU Model" $MODEL
printf "$format" "Vendor" $VENDOR
printf "$format" "Flavor" $FLAVOR


echo
for IPAddr in $inet_addrs
do
 if [ $IPAddr != "127.0.0.1" ]
 then
  if [ $os = "Linux" ]
  then
   IPAddr_name=`nslookup $IPAddr|grep -i name |awk '{print $4}'`
  else
   IPAddr_name=`nslookup $IPAddr|grep -i name |awk '{print $4}'`
  fi
  if [ ! -z ${IPAddr_name} ]; then
        printf "$format" "IPaddress-DNS"  $IPAddr-$IPAddr_name
  fi

 fi
done





Execution of the script gives output as follows:
$ ./sysInfo
Today's date is Fri Oct  3 21:26:09 SAST 2014, this is week .40.

      Processor Arch : x86_64
           Host name : myrhel.vybhava.edu
    Operating system : Linux
             Release : 2.6.18-274.el5
       Number of CPU : 24
           CPU speed : 2.67GHz
            RAM Size : 54358MB
           CPU Model : Intel(R)Xeon(R)CPUX5650@2.67GHz
              Vendor : GenuineIntel
              Flavor : RedHatEnterpriseServer

       IPaddress-DNS : 192.168.1.105-myrhel.vybhava.edu


After preparing my statistical table, reviewed and got an idea for include the disk space avaialble on every machine. That is the great result of good reviewer (my buddy did it!). So I need a disk size that I can get by df command but -lk is going to give in kilobytes, option -h works on Linux, Solaris 10 but summing up is issue so I took kilobytes and did convertions as follows:
df -lk | egrep -v "Filesystem|/proc|/dev/fd|swap|/home|/platform" | awk '
 { t += $2 }
 { u += $3}
 {GB2 = 1024*1024} END 
 { printf "%d of %d Gb in use.\n", u/GB2, t/GB2 }'
This command line excludes header, /proc, floppy, swap, user space and sun packages in /platform for Veritas.

35 of 130 Gb in use
Cheers! enjoy have fun in your work!

Good Reference:

http://www.brandonhutchinson.com/Gathering_Solaris_system_statistics.html

Keep writing your innovative ideas, generic suggestions in comments!!

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6