Wednesday, November 27, 2013

Alarm on high non-global zone memory usage

We use a lot of Solaris non-global zones for various reasons. Our tools admin enabled memory usage alarms on these ng zones and they alerted incorrectly (due to the misleading internal resource stats). We still use native resource counters to alarm on global zones, but scripted the following bit of perl to alarm when ng zones exceed a defined threshold:

use strict;
use warnings;
use Time::localtime;

my $ram_threshold = "90";

my $zones = `prstat -Z 1 1 | /usr/sfw/bin/ggrep -A 99 ZONEID | egrep -vi 'total|global|zoneid' | awk '{ print \$5","\$8 }'`;
my @zoneSplit = split("\n",$zones);

foreach my $zone (@zoneSplit) {
                my @zone_info = split(",",$zone);
                my $zone_ram = substr($zone_info[0], 0, -1);
                my $zone_name = $zone_info[1];

                if ($zone_ram gt $ram_threshold) {
                                $ConsoleMessage->MsgText("$zone_name memory exceeded $ram_threshold, value is $zone_ram");