Wrapping prstat on Solaris

skip at pobox.com skip at pobox.com
Mon Jul 27 10:26:42 EDT 2009


At work we currently use top to monitor ongoing system utilization on our
Solaris systems.  As time has moved on though, use of top has become
problematic.  Our admins want us to switch to prstat, Sun's top-like
command.  It works fine however doesn't emit a timestamp at each display
interval, so it's essentially impossible looking at a prstat output
file to determine when the particular "screen" was emitted.

If figured, "No problem.  I'll just write a little wrapper."  Alas, that is
proving harder than I thought.  I can run prstat directing output to a file
and it seems to blast out a block of lines every N seconds, but when run
from inside a Python script I can't seem to make the damn thing not
massively buffer its output.  Accordingly, my script doesn't really see the
output as its emitted, so the timestamp line it prepends to a block of
output is off.

I'm currently using subprocess.Popen like so:

    os.environ["TERM"] = "dumb"
    cmd = "prstat -c %s" % " ".join(sys.argv[1:])
    pipe = Popen(cmd, shell=True, bufsize=1, stdout=PIPE).stdout

I've tried these other variants as well:

  * prefacing the prstat command with unbuffer (the tcl/expect thingamabob)

  * explicitly redirect the prstat output to /dev/stdout

  * setting bufsize to 0

  * used os.popen instead of Subprocess.Popen

Nothing seems to help.  I always seem to see about 30 seconds of data at
once (I'm currently using a 5-second interval and 10 lines of output).  I
would have expected that prstat would simply flush stdout after each block
of output.

Any ideas about how to get prstat to cooperate better?

Thanks,

-- 
Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/
    That's more than a dress. That's an Audrey Hepburn movie. -- Jerry Maguire



More information about the Python-list mailing list