1

I'm running into a problem when using sar to collect live system statistics. When I run a sar command such as the following, I get the right output:

$ sar -r 1 -o /tmp/memory_usage Linux 4.15.0-70-generic () 29/12/20 _x86_64_ (60 CPU) 18:26:55 kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty 18:26:56 30855140 78554416 51599624 62.58 321400 48906356 3491612 4.18 25558204 23859156 36 18:26:57 30855124 78554456 51599640 62.58 321400 48906392 3491612 4.18 25558204 23859212 72 18:26:58 30855204 78554536 51599560 62.58 321400 48906424 3491612 4.18 25558204 23859212 104 18:26:59 30855188 78554576 51599576 62.58 321400 48906456 3491612 4.18 25558204 23859268 136 18:27:00 30855204 78554648 51599560 62.58 321400 48906492 3491612 4.18 25558204 23859324 172 18:27:01 30855048 78554492 51599716 62.58 321400 48906524 3491612 4.18 25558228 23859324 0 ^C Average: 30855151 78554521 51599613 62.58 321400 48906441 3491612 4.18 25558208 23859249 87 

However, when I load the output file, it seems to have only recorded the cpu usage?

$ sar -f /tmp/memory_usage Linux 4.15.0-70-generic () 29/12/20 _x86_64_ (60 CPU) 18:26:55 CPU %user %nice %system %iowait %steal %idle 18:26:56 all 0.00 0.00 0.02 0.00 0.02 99.97 18:26:57 all 0.00 0.00 0.02 0.00 0.02 99.97 18:26:58 all 0.00 0.00 0.02 0.00 0.02 99.97 18:26:59 all 0.00 0.00 0.02 0.00 0.02 99.97 18:27:00 all 0.00 0.00 0.00 0.00 0.00 100.00 18:27:01 all 0.02 0.00 0.02 0.00 0.02 99.95 Average: all 0.00 0.00 0.01 0.00 0.01 99.97 

This is my system's info:

$ uname -a Linux 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux 

I'm running sar 11.6.1, which was installed through apt, and I did not configure any cron data collection (if that matters), although I did enable the sysstat service:

$ systemctl status sysstat ● sysstat.service - Resets System Activity Data Collector Loaded: loaded (/lib/systemd/system/sysstat.service; enabled; vendor preset: enabled) Active: active (exited) since Tue 2020-12-29 16:56:29 GMT; 1h 34min ago Docs: man:sa1(8) man:sadc(8) man:sar(1) Process: 52376 ExecStart=/usr/lib/sysstat/debian-sa1 --boot (code=exited, status=0/SUCCESS) Main PID: 52376 (code=exited, status=0/SUCCESS) Dec 29 16:56:29 systemd[1]: Starting Resets System Activity Data Collector... Dec 29 16:56:29 systemd[1]: Started Resets System Activity Data Collector. 

Any idea what I'm doing wrong? Why is the memory usage not being recorded in the file? Did I misconfigure something, or is this not possible to achieve with sar? Any and all help would be greatly appreciated.

1 Answer 1

3

I'm an idiot, found the answer. Apparently when you tell sar to collect system statistics into a file, it outputs everything into it, not just the options you passed it.

So, what the command sar -r 1 -o /tmp/memory_usage is really saying is: "capture all options at a sample rate of one per second, and record them in the given file. Also, output the memory statistics to the terminal at the same rate".

Since all the stats are recorded in the output file, it can be queried with the same options as if it was live. The command sar -r -f /tmp/memory_usage outputs the memory usage collected from the file, as I expected.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.