I find the output of the shell command
top to be a simple and familiar way to get a rough idea of the health of a machine. I'd like to serve
top's output (or something very similar to it) from a tiny web server on a machine for crude monitoring purposes.
Is there a way to get top to write its textual output exactly once, without formatting characters? I've tried this:
(sleep 1; echo 'q') | top > output.txt
This seems to be close to what I want, except that (1) there's no guarantee that I won't get more or less than one screenful of info and (2) I have to strip out all the terminal formatting characters.
Or is there some other
top-like command that lists both machine-wide and process-level memory/CPU usage/uptime info?
(Ideally, I'd love a strategy that's portable to both Linux and Mac OS X, since our devs use Macs and our prod environment is Linux.)