This post is a sort of a follow up to an earlier post Quick 2 liner to measure used global zone resources in which I mentioned how we can get the compute usage details of local zones by typing just two commands. It was easy at first but then I found it painful to type both commands & then use bc again to calculate available resources by subtracting the used resources from the total resources on the global zone. So I got lazy & wrote a script to do the whole thing for me.
Here is the script:
#!/bin/bash
##script to calculate used compute resources by local zones & available CPU & RAM in a Solaris global zone##
totalcpu=0
totalram=0
for i in $(zoneadm list | grep -v global)
do
usedcpu=`zonecfg -z $i info dedicated-cpu | grep ncpus | awk '{print $2}'`
let "totalcpu += $usedcpu"
usedram=`zonecfg -z $i info capped-memory | grep physical | awk '{print $2}'| tr -d "G"`
let "totalram += $usedram"
done
##Print used resources##
echo -e "total used CPUs is:" $totalcpu
echo -e "total used RAM in GB is:" $totalram
##Set total resources in global zones##
allocatedcpu=512
allocatedram=1024
##calculate free resources##
availablecpu=$(expr $allocatedcpu - $totalcpu)
availableram=$(expr $allocatedram - $totalram)
##Print free resources##
echo -e "free cpu count is:" $availablecpu
echo -e "free RAM in GB is:" $availableram
##end of script##
Here is the output from a sample run:
total used CPUs is: 388
total used RAM in GB is: 944
free cpu count is: 124
free RAM in GB is: 80
Here is the script:
#!/bin/bash
##script to calculate used compute resources by local zones & available CPU & RAM in a Solaris global zone##
totalcpu=0
totalram=0
for i in $(zoneadm list | grep -v global)
do
usedcpu=`zonecfg -z $i info dedicated-cpu | grep ncpus | awk '{print $2}'`
let "totalcpu += $usedcpu"
usedram=`zonecfg -z $i info capped-memory | grep physical | awk '{print $2}'| tr -d "G"`
let "totalram += $usedram"
done
##Print used resources##
echo -e "total used CPUs is:" $totalcpu
echo -e "total used RAM in GB is:" $totalram
##Set total resources in global zones##
allocatedcpu=512
allocatedram=1024
##calculate free resources##
availablecpu=$(expr $allocatedcpu - $totalcpu)
availableram=$(expr $allocatedram - $totalram)
##Print free resources##
echo -e "free cpu count is:" $availablecpu
echo -e "free RAM in GB is:" $availableram
##end of script##
Here is the output from a sample run:
total used CPUs is: 388
total used RAM in GB is: 944
free cpu count is: 124
free RAM in GB is: 80
No comments:
Post a Comment