Forum OpenACS Q&A: Monitoring Package: How do I get the top stats to work?

I am setting up the monitoring package and I am not able to get top to run. I am getting the following error:

---------------
top could not be run
The top procedure at /usr/bin/top cannot be run:

TERM environment variable not set.
---------------

From email sent by the Monitoring package:

"Error: ad_monitor_top: top could not be run - TERM environment variable not set."

Quick check:

su - service0
service0@myserver:~$ which top
/usr/bin/top
service0@myserver:~$ echo $TERM
xterm-color

I could not find any place in the OpenACS admin pages to set TERM. There is nothing posted about it in the forums. How do I get this to work?

Had another mail in my inbox with the same error message rather than useful stats and it motivated me to look at the problem again.

If I start up a tclsh and type "exec top -bn1" it does what I want it to do. If I run the same command from within the OpenACS Shell I get the same error: "top could not be run - TERM environment variable not set".

Using the the OpenACS shell I set TERM to vt100 and all of a sudden I am able to run top with the batch flag so the package can do its magic: guess the package was written for more prehistoric forms of top (I assume newer versions of top require the TERM variable to do some fancy interactive formatting).

So now my question is:

Where/how do I set the environment variables of the nsd process on startup so this continues to work after a restart AOLServer?

Where/how do I set the environment variables of the nsd process on startup so this continues to work after a restart AOLServer?

You should be able to set env vars in the nsd-postgres wrapper script that starts up aolserver.

Another place is in the openacs-4/etc/daemontools/run script. The default install of OpenACS does not use nsd-postgre/oracle.
Thanks. Tekbase helped on #aolserver too. I want to get monitoring working correctly by default. Does it make sense to add TERM=vt100 (or something else) to the run script? Seems kind of strange to add it there, but I could not find any flags in the top man pages that force it to run without asking for $TERM. What is the best thing to do in this case. Go ahead and add the variable? Add it as a comment (and add some documentation to the package)? Let me know and I will do it.
The other thing you could do is to export the TERM var when you call top.
export TERM=vt100; top -bn 1
That way you wouldn't have to restart the server if you needed to change the TERM for any reason.