A co-worker asked the following question ...

"We have been running into some issues at customer sites recently where customers are running zones and trying to determine which zone is hogging resources.  For example, we have a customer monitoring with CA-Unicenter and the agent on the zone reports CPU utilization for the entire system, not just the local zone.  If CPU utilization gets high, all the local zones report it high and they have no way of knowing which zone is the hog unless they login to the global zone."

If you're logged on to the system, you can run prstat -Z to generate a summary of cpu/memory utilization by zone. But as the number of zoned hosts in your data center grows, this becomes impractical. I suggested the following web server script which screen-scrapes the prstat -Z output, refreshing itself every 5 seconds.

This cgi-bin script can be deployed to any solaris apache server's cgi-bin directory ...
    # cat prstat
    #!/bin/sh

    echo "Content-type: text/html; charset=iso-8859-1\n"

    echo "<meta HTTP-EQUIV=REFRESH content=5>
      <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
      \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\">"

    echo "<head>
      <title>Resource Summary for host `hostname` </title>
    </head>
    <body>
      <table border=1>"
      /usr/bin/prstat -c -n 1 -Z 1 1 | /usr/bin/grep -v Total: | /usr/bin/awk 'BEGIN{getline;getline;}{printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $8,$7,$5,$2); }'
    echo "  </table>
    </body>
    </html>"

To view zone utilization summary: http://[hostname]/cgi-bin/prstat

Here's a php version of the same script for those of you with a newer opensolaris release . The newer opensolaris builds (within the last 6 months) have a bundled apache/php stack whiich is a piece of cake to enable - it's no longer necessary to download and compile php for apache !


php version, deploy to your /var/apache2/2.2/htdocs (DocumentRoot) directory:

    # cat prstat.php
    <meta HTTP-EQUIV="REFRESH" content="5">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Resource Summary for host <?php passthru("hostname");?></title>
    </head>
    <body>
      <table border=1>
      <tr><th colspan=4>Host: <?php passthru("hostname");?></th></tr>
      <?php passthru("/usr/bin/prstat -c -n 1 -Z 1 1 | /usr/bin/grep -v Total: | /usr/bin/awk     'BEGIN{getline;getline;}{printf(\"<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\\n\", $8,$7,$5,$2); }'"); ?>
    </table>
    </body>
    </html>

To view zone utilization summary: http://[hostname]/prstat.php

Do you have another solution ? Please post a comment to my blog at

http://blogs.sun.com/jayd

Comments:

If the goal was to find the "CPU hog" zone, couldn't you just use prstat's built sorting functionality? For example, something like:

prstat -Z -s cpu

That would list the CPU hog at the top of the list, right?

Posted by BBB on July 25, 2008 at 10:16 AM EDT #

Yes, absolutely. But the point of this post was how to get this information remotely, when I have a data center full of zoned systems ... I was offering an alternative that eliminates the need to log on to each host and run a command. And when using prstat in a web server script, I can only take one sample, it's not free running as when used from the command line. Thus the reason for this invocation of prstat in the script: '/usr/bin/prstat -c -n 1 -Z 1 1'

Posted by jay on August 01, 2008 at 09:10 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by Jay Danielsen