Friday, October 19, 2007

Run monitoring program in a TTY

I remembered seeing something really cool in a live CD distro. On some TTYs they ran some nice monitoring programs so that I could keep an eye on system resources just by switching to a TTY. I finally got around to looking it up.

First, install htop, which is like top on steroids. In a Debian-based system, run:
apt-get install htop

To run htop whenever the system boots, you need to modify one file. In a traditional SysV init system, you can place a line like this in inittab:
6:2345:respawn:exec /usr/bin/htop >/dev/tty6 </dev/tty6

If you're running a distro that uses Upstart, like later Ubuntu releases, then put this in /etc/event.d/tty6:
start on runlevel 2
start on runlevel 3

stop on runlevel 0
stop on runlevel 1
stop on runlevel 4
stop on runlevel 5
stop on runlevel 6

exec /usr/bin/htop >/dev/tty6 </dev/tty6

Now issue:
sudo kill -HUP 1

[Edit] or alternatively:
sudo stop tty6; sudo start tty6

Press Ctrl-Alt-F6 and you'll see a very cool system monitor. Some other options for monitoring include:
exec /usr/bin/top d 1 s S c >/dev/tty6 </dev/tty6 # Classic top
exec /usr/sbin/iftop -i eth1 >/dev/tty6 </dev/tty6 # Monitor network interface

Keep in mind that if you want to run more than one, you'll have to put each one on a different TTY. Have fun!


No comments: