Howto collect Linux system utilization data into a file

last updated in Categories CentOS, Debian Linux, Gentoo Linux, Howto, Linux, Monitoring, RedHat/Fedora Linux, Suse Linux, Sys admin, Tips, UNIX

I’ve already documented the procedure to find out CPU utilization under Linux and UNIX oses using various tools.


However I received a couple of email questions via email:

Howdo I collect Linux system utilization data into a file? How do I email the data or move to another computer?

To be frank you don’t have to do anything data is collected and stored in /var/log/sa location using sa1 and sa2 scripts. It is part of sadc – System activity data collector tools.

The sadc command samples system data a specified number of times ( count ) at a specified interval measured in seconds ( interval ). It writes in binary format to the specified output file.

The sa1 command is a shell procedure variant of the sadc command and handles all of the flags and parameters of that command. The sa1 command collects and store binary data in the /var/log/sa/sadd file, where the dd parameter indicates the current day. The interval and count parameters specify that the record should be written count times at interval seconds.

The sa1 command is designed to be started automatically by the cron command. Type the following command to list files:
# ls /var/log/sa

sa13  sa14  sa15  sa16  sa17  sa18  sa19  sa20  sa21  sar12  sar13  sar14  sar15  sar16  sar17  sar18  sar19  sar20

How do I copy log files?

You can copy all these logs files using ssh/scp or ftp to another computer. You can run use sar command to read binary raw data files, enter
# sar -f sa13

Linux 2.6.9-55.ELsmp (     05/13/2007

12:00:02 AM       CPU     %user     %nice   %system   %iowait     %idle
12:10:01 AM       all     19.75      0.00      2.29      7.49     70.48
12:20:01 AM       all      2.28      0.00      0.27      0.06     97.39
12:30:01 AM       all      2.58      0.00      0.32      0.07     97.02
12:40:02 AM       all     16.05      0.00      3.12     13.48     67.36
12:50:01 AM       all     10.78      0.00      1.20      3.61     84.41
01:00:01 AM       all      2.42      0.00      0.29      0.30     96.99
01:10:01 AM       all      3.70      0.00      0.42      0.42     95.47
01:20:01 AM       all      2.47      0.00      0.28      0.14     97.11
01:30:01 AM       all      3.20      0.00      0.31      0.15     96.34
01:40:01 AM       all      2.46      0.00      0.27      0.07     97.20
01:50:01 AM       all      2.40      0.00      0.26      0.10     97.24

See also:


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

5 comment

  1. I cannot see any sadc command, which package do I need to install to get this command..
    I can see sadf and the man refer to something this
    “The sadf command is used for displaying the contents of data files cre-
    ated by the sar(1) command.”

    and as far as sa”x” belongs I used to convert it in different format, but I dont understand we can look in the sar file for the related answer

  2. The sarDD reports saved by sar utility stores entire activity, but I am interested in only the CPU and memory utlization.I want to retrieve this data and store it in some DB for displaying it in presentable format.One way for that will be to read this file using my program and then search for string like ‘CPU’ and ‘mem’ and then retrieve the corresponding block and then save it in database.Is there any other ways around? can i change/ update sar to store data which I am interested in?
    Please help with any inputs.

    Have a question? Post it on our forum!