1752720 Members
5572 Online
108789 Solutions
New Discussion юеВ

sar -d formatting

 
SOLVED
Go to solution
KPS
Super Advisor

sar -d formatting

I have a very large sar output file and from it I have extracted the sar -d info to a text file as follows:

sar -d -f sa07 > sa07-disk.out

Now what I'm trying to figure out is if there's any way to get dates in front of every entry in my output by reformatting it via a script or set of commands.. I'm ultimately trying to import this data into a spreadsheet to sort and look at highest to lowest colums, but I also need to know the times for each of the entries I'm interested in.

Any ideas that can be shared would be greatly appreciated.

Thanks,
/KPS
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: sar -d formatting

You have some sample output from sa07-disk.out?
VK2COT
Honored Contributor
Solution

Re: sar -d formatting

Hello,

Several years ago, I did just that. Albeit,
it was for Solaris servers but the logic
is the same.

Here is the Perl script:

#!/usr/bin/perl

# 00:00:00 device %busy avque r+w/s blks/s avwait avserv

#use strict;
use Getopt::Std;
use File::Basename;

use vars qw(@Header $z %Disk %RW @Keyspaces @Onetime $Time
$FF $SAFile $Disk @WholeComplex $RW %WholeComplex @Servdata
$Realmonth $Month $Sec $Min $Hour $DayOfMonth $Month $Year
$Result $FR $DayOfWeek $DayofYear $IsDST);

($Sec, $Min, $Hour, $DayOfMonth, $Month, $Year, $DayOfWeek, $DayofYear, $IsDST) = localtime ;

# localtime returns January..December as 0..11.
$Realmonth = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)[$Month];
$Month++;
$Year = 1900 + $Year;

($::opt_f) = (); #avoid warning message
getopts('f:');
$::SAFile = $::opt_f;

if (! "$SAFile" ) {
$FF = "";
} else {
$FF = "-f $SAFile";
}

$FR = basename($SAFile);

print "Processing SAR file $SAFile ($FR)\n";

$Result1 = "/mydir/mysrv-sar-data/${FR}${Realmonth}${Year}-DISK_RWS.txt";
$Result2 = "/mydir/mysrv-sar-data/${FR}${Realmonth}${Year}-DISK_BUSY.txt";
$Result3 = "/mydir/mysrv-sar-data/${FR}${Realmonth}${Year}-DISK_AVSERV.txt";

open(To1, ">$Result1") or die "ERROR: Can't open $Result: $!";
open(To2, ">$Result2") or die "ERROR: Can't open $Result: $!";
open(To3, ">$Result3") or die "ERROR: Can't open $Result: $!";

open(FROM,"sar -d $FF | awk '! /%/ && ! /,/ {print}'|") || die "Cannot open sar data";
while () {
chomp;
if (/:/ .. /^$/) {
@Keyspaces = split(/\s+/, $_);
if (grep(/:/, $_)) {
$Time = $Keyspaces[0];
printf To1 "\n$Time ";
printf To2 "\n$Time ";
printf To3 "\n$Time ";
if (! grep(/\bTimeStamp/, @Header)) {
push @Header, "\nTimeStamp ";
}
}

$Disk{$Time} = $Keyspaces[1];
$Busy{$Time} = $Keyspaces[2];
$Avserv{$Time} = $Keyspaces[$#{Keyspaces}];
$RW{$Time} = $Keyspaces[4];
printf To1 "$RW{$Time} ";
printf To2 "$Busy{$Time} ";
printf To3 "$Avserv{$Time} ";
if (! grep(/\b$Disk{$Time}/, @Header)) {
push @Header, "$Disk{$Time} ";
}
}
}

printf To1 "@Header\n";
printf To2 "@Header\n";
printf To3 "@Header\n";
exit(0);

In this specific case, I save different
metrics into different files, but it
is quite easy to put them into the same file :)

I also just tested my old script on Fedora 10
server and it worked. Here are parts of
myhost-sa15Jan2009-DISK_RWS.txt:

...
10:30:01 0.00
10:30:01 0.00
10:30:01 0.00
10:30:01 0.00
10:30:01 0.00
10:30:01 0.00
10:30:01 4.33
10:30:01 4.33
10:30:01 4.33
10:30:01 0.00
10:30:01 0.00
10:40:01 0.03
10:40:01 0.00
10:40:01 0.00
10:40:01 0.00
...

I hope it helps you,

VK2COT
VK2COT - Dusan Baljevic
VK2COT
Honored Contributor

Re: sar -d formatting

By the way, here is how raw sar files look like
(so that you can compare them with what
gets reported via my Perl script):

Linux 2.6.27.9-159.fc10.i686 (bmyhost.mydom.dom) 01/16/2009

12:00:02 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz awai
t svctm %util
12:10:02 AM dev8-0 0.71 1.20 17.36 26.33 0.03 39.9
0 1.19 0.08
12:10:02 AM dev8-1 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00
12:10:02 AM dev8-2 0.40 0.00 8.09 20.49 0.02 42.7
6 1.11 0.04
12:10:02 AM dev8-3 0.29 0.53 9.17 33.47 0.01 37.2
5 2.67 0.08
12:10:02 AM dev8-4 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00
12:10:02 AM dev8-5 0.02 0.67 0.09 38.00 0.00 22.0
8 22.00 0.04
12:10:02 AM dev8-6 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00
12:10:02 AM dev8-7 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00
12:10:02 AM dev8-16 0.00 0.00 0.00 0.00 0.00 0.0
0 0.00 0.00

VK2COT
VK2COT - Dusan Baljevic
KPS
Super Advisor

Re: sar -d formatting

We're all set here, thanks for the recommendation V2COT.

/KPS