2

Is there a way to just display a given days averages using sar. I currently do something like the following:

sar -u -s 00:00:00 -e 23:59:59 -f /var/log/sysstat/sa10

And just take the last (average) line to add to a report. But it would be nice and easy to just gen my report if I could pass an argument to just spit-out the average. I could not find such an option in the sar documentation. So, unless I am missing it, I am guessing the option is no. However, It's very possible I'm missing it or there might be another tool other than sar that might expose this functionality.

  • 1
    Is this is what you are looking for? sar -u -s 00:00:00 -e 23:59:59 -f /var/log/sysstat/sa10 | tail -1 – Ramesh Apr 28 '14 at 1:52
  • 1
    @Ramesh - write that up as an A. That's the way to do it. – slm Apr 28 '14 at 2:54
3

You can find the average by piping the tail command to your command. By this way, your command will always return only one line.

sar -u -s 00:00:00 -e 23:59:59 -f /var/log/sysstat/sa10 | tail -1
|improve this answer|||||
0

Not using sar...but there are accounting utilities in that package that will help you on a given days' worth of SAR output. This is usually installed as a crontab entry (commented out) running as adm or sys sometimes as root. In later linux versions, it is installed as /etc/cron.d/sysstat. Look at the sa1 and sa2 commands. They are /usr/lib64/sa/sa1 and sa2 and work as a team. sa1 stores data in binary form when called and sa2 takes the binary file from sa1 and generates a textual report containing the averages.

There is ample information on this scheme, just do an appropriate google search like 'linux sa utilities'.

|improve this answer|||||
0

Using tail requires you to know how many lines you anticipate of average statistics. If you want average stats for each cpu and you have used -P ALL then the tail command is cumbersome.

I suggest simply grep'ing for Average. To get the header, which is a comment inserted by sadc, you need to add the -C option:

# sar -P ALL -C | grep Average:
Average:        CPU     %user     %nice   %system   %iowait    %steal     %idle
Average:        all      3.06      0.00      1.22      0.00      0.00     95.72
Average:          0      0.55      0.00      0.23      0.01      0.00     99.21
Average:          1      1.96      0.00      0.77      0.00      0.00     97.26
Average:          2      3.84      0.00      1.63      0.00      0.00     94.52
Average:          3      0.59      0.00      0.24      0.00      0.00     99.17
Average:          4      0.51      0.00      0.27      0.01      0.00     99.21
Average:          5      1.78      0.00      0.74      0.01      0.00     97.47
Average:          6      8.02      0.00      3.16      0.01      0.00     88.81
Average:          7      6.75      0.00      2.61      0.00      0.00     90.64
Average:          8     10.93      0.00      4.20      0.01      0.00     84.86
Average:          9      6.47      0.00      2.54      0.01      0.00     90.98
Average:         10      9.76      0.00      3.72      0.02      0.00     86.50
Average:         11      5.42      0.00      2.03      0.01      0.00     92.54
Average:         12      0.07      0.00      0.05      0.00      0.00     99.89
Average:         13      0.31      0.00      0.18      0.00      0.00     99.51
Average:         14      0.02      0.00      0.21      0.00      0.00     99.78
Average:         15      0.06      0.00      0.08      0.00      0.00     99.86
Average:         16      0.14      0.00      0.07      0.00      0.00     99.79
Average:         17      0.03      0.00      0.04      0.00      0.00     99.93
Average:         18      8.03      0.00      3.16      0.00      0.00     88.80
Average:         19      1.41      0.00      0.56      0.00      0.00     98.02
Average:         20      2.62      0.00      1.06      0.00      0.00     96.32
Average:         21      0.37      0.00      0.16      0.00      0.00     99.47
Average:         22      0.07      0.00      0.04      0.00      0.00     99.89
Average:         23      3.66      0.00      1.43      0.00      0.00     94.90
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.