Log module command¶
It is sometimes desired to better understand the module
usage on the
system we manage. Especially to determine what are the modulefiles most used
and what are those never used that could be removed. This recipe describes a
way to track the module
usage by logging each request made.
Implementation¶
Logging module commands is implemented by the use of a site-specific
configuration that supersedes the definition of the module
command to
execute the logger
command, in order to send a message to the system log,
prior processing the module command itself. The log message sent describes the
module command called and who called it.
# override 'module' procedure to log each call made by user
rename ::module ::__module
proc module {command args} {
if {[getEvalModuleStackDepth] == 0} {
exec logger -t module "[get-env USER]: $command [join $args]"
}
return [eval __module "{$command}" $args]
}
Compatible with Modules v4.2+
Installation¶
Create site-specific configuration directory if it does not exist yet:
$ mkdir /usr/share/Modules/etc
Then copy there the site-specific configuration script of this recipe:
$ cp example/log-module-commands/siteconfig.tcl /usr/share/Modules/etc/
Note
Defined location for the site-specific configuration script may vary from
one installation to another. To determine the expected location for this
file on your setup, check the value of the siteconfig
option on Modules
version 4.3 or above:
$ module config siteconfig
On older version of Modules, check the modulecmd.tcl
script:
$ grep '^set g_siteconfig ' $MODULES_CMD
Usage example¶
Loading a bare modulefile:
$ module load example
A log entry can then be retrieved from system log files:
$ journalctl -q -t module -n 1
Sep 12 20:24:01 hostname module[9925]: username: load example