4

I am trying to input multiple sar files for a graph I am generating. I can input the files one at a time like so:

LC_ALL=C sar -A -f /var/log/sa/sa05 >> /tmp/sar.data3.txt

This systax does not work, but this is the idea of what I'm trying to do:

LC_ALL=C sar -A -f /var/log/sa/sa* >> /tmp/sar.data3.txt

user3795293
  • 41
  • 1
  • 2

3 Answers3

1

sa* files seems to be binary files i.e. cat on one of the saXX file will not echo valid human readable words. The following can be used to see its human readable contents.

strings /var/log/sa/sa01 or saXX 

The file you might need is sarXX: you can try "LC_ALL=C ...." command as you mentioned above in place of just what I mentioned below.

for file in /var/log/sa/sar*; do sar -A -f "$file"  >> /tmp/sar.data3.txt; done

Now, the following command will show/have what you need.

cat /tmp/sar.data3.txt 

I didn't see all the options of SAR command, would recommend you to check if there is any which would support sar* or sar??

chepner
  • 497,756
  • 71
  • 530
  • 681
AKS
  • 16,482
  • 43
  • 166
  • 258
1

You can use the find command to aggregate the files and concatenate them into your output file with something similar to:

find /var/log/sa -type f -name "sa*" \
-exec LC_ALL=C sar -A -f '{}' >> /tmp/sar.data3.txt \;

What you are attempting to do looks to be failing due to sar not accepting multiple input files with the -f option. In the future, you may consider using the -o option to prepare files containing the data you want in records that can later be output with the -f option

David C. Rankin
  • 81,885
  • 6
  • 58
  • 85
1

To see the multiple-day sar report for memory stats:

find /var/log/sa/ -type f|grep sar|xargs grep kbmem -A144

To see the CPU status, try this

find /var/log/sa/ -type f|grep sar|xargs grep "CPU     %user" -A720

How it works

The directory /var/log/sa/ will have files such as sar23, sar24, sar25, sar26, sar27. The sar-suffix corresponds to the day of the month.

  • First find and grep only the sar-suffix files
  • Then pass the sar files as argument to the "grep keyword" command. This will give you only the header of the parameter you are interested in (kbmem for memory, or "CPU %user" for cpu status)
  • But you would also like the next 144 lines after the header for memory details (or 720 lines for CPU). So include the -A144 or -A720 options to the grep command.

Note:

  • For memory stats, a single line is logged every 10 mins. Hence 144 lines per day.
  • For CPU stats, 5 lines are logged every 10 mins, hence 720 lines per day (at least in my env). This might be different in your env, so please verify or calculate this manually at your end.

If you love aliases:

alias sarcpu='find /var/log/sa/ -type f|grep sar|xargs grep CPU     %user -A720'
alias sario='find /var/log/sa/ -type f|grep sar|xargs grep bread -A144'
alias sarmem='find /var/log/sa/ -type f|grep sar|xargs grep kbmem -A144'
Thyag
  • 1,217
  • 13
  • 14