May.11

Solaris disk utilization(including zones) script & sending to mysql

HI

I have been writing scripts to automate my solaris admin tasks. currently i am handling more than 250 sun servers and my primary focus area is solaris nowadays. Somehow linux came to 2nd priority

today i am posting some script to monitor disk utilization of solaris server including zones(containers). And this script will send result to mysql database directly .you need to run this script on global zone and you than set the disk check threshold value also.

To connect to mysql, you need to install mysql-client package. ie simple compile & make. you can download mysql-client from http://dev.mysql.com/downloads/mysql/5.1.html. For compiling this package , you need Compilers and other development tools. You can get all this from sun studio. Install sun studio and include studio in your PATH.

 

#!/bin/bash
#Created By – Ben George – ben@benvin.net
IFS=$’\n’ read -d ” -ra filesystem < <(df -h | egrep -e ‘/dev/dsk|pool’)
IFS=$’\n’ read -d ” -ra zonename < <(zoneadm list)
DATE=$(/usr/bin/date |awk ‘{print $3″-“$2”-“$6}’)
ipaddress=$(ifconfig -a | grep inet | grep -v ‘127.0.0.1’ | awk ‘NR>1{ print $2}’| head -1)
for i in “${!zonename[@]}”;do

if [ “${zonename[$i]}” = “global” ];then
for i in “${!filesystem[@]}”;do
percentage=$(echo “${filesystem[$i]}” | awk ‘{print $5}’ | sed ‘s/%/ /g’)
if [ $percentage -gt 50 ];then
mountpoint=$(echo “${filesystem[$i]}” | awk ‘{print $6}’)
echo $HOSTNAME $ipaddress $mountpoint “:” $percentage”%”
/opt/mysql/bin/mysql –host=172.16.99.182 –user=root –password=Redhat server_daily << EOF
insert into filesystem (hostname,ipaddress,time,filesystem_name,percentage) values(‘$HOSTNAME’,’$ipaddress’,’$DATE’,’$mountpoint’,’$percentage’);
EOF
fi
done
else
echo “${zonename[$i]}”
IFS=$’\n’ read -d ” -ra zonefilesystem < <(zonecfg -z “${zonename[$i]}” info | egrep ‘pool|dir:’ | awk ‘{print $2}’)
for j in “${!zonefilesystem[@]}”;do
echo “${zonefilesystem[$j]}” | while read n;do
zonepercentage=$(zlogin “${zonename[$i]}” df -h “${zonefilesystem[$j]}” | awk ‘NR>1{print $5}’ | sed ‘s/%/ /g’)
if [ $zonepercentage -gt 50 ];then
zone_mountpoint=$(zlogin “${zonename[$i]}” df -h “${zonefilesystem[$j]}” | awk ‘NR>1{print $6}’)
zone_hostname=$(zlogin “${zonename[$i]}” hostname)
zone_ip=$(zlogin “${zonename[$i]}” ifconfig -a | grep inet | grep -v ‘127.0.0.1’ | awk ‘{ print $2}’)
echo $zone_hostname $zone_ip $zone_mountpoint “:” $zonepercentage”%”
/opt/mysql/bin/mysql –host=172.16.99.182 –user=root –password=Redhat server_daily << EOF
insert into filesystem (hostname,ipaddress,time,filesystem_name,percentage) values(‘$zone_hostname’,’$zone_ip’,’$DATE’,’$zone_mountpoint’,’$zonepercentage’);
EOF
fi
done
done
fi
done

 

Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u

Leave a comment