Q. How do I install sar command under FreeBSD to collect, report, or save system activity information? How can I setup freebsd accounting?A. . sar, sa1, sa2 and sadc commands are for SysV system such as Linux.

You need to install a package called bsdsar under FreeBSD. It is a system activity reporter (SAR) for FreeBSD systems. It stores or shows information on network, cpu, memory, swap, and NFS usage. Data is polled at intervals - usually every 20minutes during the day, and hourly in evening/night hours and is stored for later usage.

Install bsdsar

Configure bsdsar

Open configuration file /usr/local/etc/bsdsar.conf:# vi /usr/local/etc/bsdsar.conf Usually you need to configure the data gathering section. To turn ON gathering of data, put the word "on" after the type of data to gather. To turn it off, put "off" after the data type to turn that gathering off. All is on by default. For example turn off nfs data gathering, modify as follows:nfs = off Here is my own working sample config file:

sa command -- print system accounting statistics

sa is another preferred tool under FreeBSD to print system accounting statistics. First, you must turn on system accounting, open /etc/rc.conf file:# vi /etc/rc.conf Turn on accounting by entering following code:accounting_enable="YES" Save and close the file. Start accounting service# /etc/rc.d/accounting start

How do I view statistics

To list all command names, including those containing unprintable characters and those used only once, enter:# sa -a Sort by the average number of disk I/O operations for each user command, enter:# sa -d To print total number of disk I/O operations, enter:# sa -D

Show last commands executed

Use lastcomm command to display information on previously executed commands:# lastcomm Above command will display information about all the commands recorded during the current accounting file's lifetime. To print the exit time and elapsed time of each command, enter:# lastcomm -Ee To print user vivek's all command, enter:# lastcomm vivek