Tuesday 25 October 2016

Quick 2 liner to measure used global zone resources

I have a situation where I have a lot of local zones with capped resources running on my global zones.

root@myglobalzone:~# zoneadm list | grep -v global
localzone60051
localzone60043
localzone60063
localzone30025
localzone60049
localzone30061
localzone60039
localzone60105
localzone60101
localzone60161
localzone50059
localzone30081
localzone30035
localzone30083

I need to find the total capped physical memory & the dedicated CPUs used by the local zones so that I can ascertain if the global zone can accommodate more local zones.

I could measure the used capacities by checking the zonecfg for each zone one by one, noting it down & summing the total. That would be a boring and time consuming process.

Here is a quick 2 line trick to get the required information within seconds:

root@myglobalzone:~#  for i in $(zoneadm list | grep -v global); do zonecfg -z $i info dedicated-cpu | grep ncpus | awk '{print $2}'| tr "\n" "+" ; done
16+16+4+48+16+4+16+8+8+8+12+128+32+64+root@myglobalzone:~#

root@myglobalzone:~# echo "16+16+4+48+16+4+16+8+8+8+12+128+32+64+" | sed "s/.$/ /"  | bc
380
root@myglobalzone:~#
root@myglobalzone:~# for i in $(zoneadm list | grep -v global); do zonecfg -z $i info capped-memory | grep physical | awk '{print $2}'| tr "\n" "+" |tr -d "G"; done
16+16+8+64+16+12+16+16+16+16+36+192+32+64+root@myglobalzone:~#

root@myglobalzone:~# echo "16+16+8+64+16+12+16+16+16+16+36+192+32+64+"  | sed "s/.$/ /"  | bc
520

Hope this time saver helps!

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...