2

Task:

I can sar -u > tmp.csv and I can sar -r > tmp.csv But what I need is a big table of all the sa* files of all the options.

sar -r -u -S -q > tmp.csv

does not quite do the job

Problems

The length of sar -r and lets say sar -u might be different. For one of them I had 3625, for the other 3650 and that is not acceptable.

Possible solution

for each sa* file I do sar -r sa* > sar_r_sa*.csv, I do that for -r -u -S -q and I get about 120 files of data which I could somehow merge with Python by the first column e.g. ( 7,50,01 ).

But I feel like there is a easier solution to the problem.

Question

How should I approach collecting all the data in a single file

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
murloc
  • 55
  • 1
  • 9
  • Is this what you want in your output .. `CPU %user %nice %system %iowait %steal %idle kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit` ... ? – ss_iwe Aug 02 '18 at 13:02
  • I want data for all column `%user,..,%idle,...kbmemused,....,ldavg-1` but if you suggest a approach for `sar -u` and `sar -r`, I would figure for the rest. **IN SHORT, YES** – murloc Aug 02 '18 at 13:17

2 Answers2

2

Try this:

paste <(sar -r) <(sar -u) <(sar -q) <(sar -S) > sar.out

A sample output:

12:00:01 AM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit   12:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle 12:00:01 AM   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
12:10:01 AM   1737724   6311336     78.41     22036     85856   5583532     45.60   12:10:01 AM     all      3.92      0.00      8.85      0.01      0.00     87.22 12:10:01 AM         2       872      1.00      1.00      1.00
12:20:01 AM   1737228   6311832     78.42     22484     85860   5582312     45.59   12:20:01 AM     all      3.93      0.00      8.83      0.01      0.00     87.23 12:20:01 AM         2       871      1.00      1.01      1.00
12:30:01 AM   1736764   6312296     78.42     22956     85852   5582192     45.59   12:30:01 AM     all      3.96      0.00      8.79      0.01      0.00     87.24 12:30:01 AM         2       871      1.00      1.00      1.00
12:40:01 AM   1735636   6313424     78.44     23420     85868   5582264     45.59   12:40:01 AM     all      3.92      0.00      8.85      0.01      0.00     87.22 12:40:01 AM         2       871      1.00      1.00      1.00
12:50:01 AM   1734644   6314416     78.45     23884     85872   5582248     45.59   12:50:01 AM     all      3.90      0.00      8.86      0.01      0.00     87.22 12:50:01 AM         2       871      1.00      1.00      1.00
01:00:01 AM   1733992   6315068     78.46     24356     85876   5582252     45.59   01:00:01 AM     all      3.95      0.00      8.79      0.01      0.00     87.24 01:00:01 AM         2       871      1.00      1.00      1.00
01:10:01 AM   1731508   6317552     78.49     24836     85892   5583444     45.60   01:10:01 AM     all      3.95      0.00      8.80      0.01      0.00     87.24 01:10:01 AM         2       872      1.00      1.00      1.00
01:20:01 AM   1732028   6317032     78.48     25304     85880   5582144     45.59   01:20:01 AM     all      3.95      0.00      8.80      0.01      0.00     87.24 01:20:01 AM         2       871      1.00      1.00      1.00
01:30:01 AM   1730776   6318284     78.50     25752     85888   5582324     45.59   01:30:01 AM     all      3.95      0.00      8.79      0.01      0.00     87.25 01:30:01 AM         2       871      1.00      1.00      1.00
01:40:01 AM   1729152   6319908     78.52     26224     85892   5582404     45.60   01:40:01 AM     all      3.95      0.00      8.79      0.01      0.00     87.25 01:40:01 AM         2       871      1.00      1.00      1.00

Note: You would be having duplicate time columns in the final output

ss_iwe
  • 1,136
  • 6
  • 12
1

You can try with join to collect all the data in a single file:

join <(join <(sar -q) <(sar -S)) <(join <(sar -u) <(sar -r))
Siva
  • 9,017
  • 8
  • 56
  • 86
  • My issue is that in some sar files there is no records for specific options. It's mandatory that the date is synced. Do you think that `join -j 1 f1 f2` would do the job? – murloc Aug 03 '18 at 07:11