3

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.

2
  • 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 Commented Apr 28, 2014 at 1:52
  • 1
    @Ramesh - write that up as an A. That's the way to do it. Commented Apr 28, 2014 at 2:54

3 Answers 3

5

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 
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'.

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 

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.