1821410 Members
2944 Online
109633 Solutions
New Discussion юеВ

Reading SAR output

 
Ralph Grothe
Honored Contributor

Reading SAR output

Here's a question for C system hackers,

as a cronjob I have sar write a record every 10 mins. during office hours to be later inspected for system stats.
I know there are much fancier tools such as perfview, but I wanted to collect the data numerically first before polishing it up by charts or so.
Because it has been quite some time since I've coded anything in C, and meanwhile I'm spoiled by the ease to do things in Perl, I found it somewhat difficult to sift through all the system header files.
At the moment I'm simply parsing the output from sar in a loop like this:

open SAR, "/usr/sbin/sar -$SARFMT{saropt}->{FLAG} -f $LOGDIR/$safile |"
|| die "couldn't pipe to sar:$!n";
while () {
# do anything
}
close SAR;

Although this approach works satisfactorily I don't want to rely on the external sar command to read sar's binary data.
So I had a look at the sa1 manpage which contains a rough description of the sa struct.
The problem to me is the deep nesting of other structs in it, and to find all the dependant header files in order to form a template for Perl's pack function which would give me a chance to read sar's binary data files.
(e.g. the mentioned sysinfo.h in the manpage doesn't contain a definition of the struct sysinfo, but instead of the structs ksysinfo and ksysinfo32, so which one to use?).
Has anyone written a script/prog to read sar's binary data who could give me a description of the required data types?

Many thanks for your attention
Ralph
Madness, thy name is system administration
5 REPLIES 5
Carlos Fernandez Riera
Honored Contributor

Re: Reading SAR output


I've do somethig like that, but finaly i used sar -f and get data in ascii.

Why? Maybe sar structures may change and all my code must be revised.

Hope this helps.


unsupported
Rick Garland
Honored Contributor

Re: Reading SAR output

The tool sa2 to convert the binary sar data to ascii is already present on the system. The output will include the numerical data with the date and time it was collected.
Ralph Grothe
Honored Contributor

Re: Reading SAR output

Carlos,

about the possible changes of data structure in future OS releases you are probably right.
And by now the whole subject doesn't seem to me to be worth the effort of delving in sar's binary data format since my script is working with sar itself fine.
So why bother?

Rick,

thanks for the hint.
I had a short glance in /usr/lbin/sa/sa2 but I cannot see much difference to my solution because this script is also relying on the sar command itself to retrieve the stored binary data.

Thank you to both of you for your assistance.

Regards
Ralph

Madness, thy name is system administration
Carlos Fernandez Riera
Honored Contributor

Re: Reading SAR output


Well, you can write a program to read and translate binary data form /var/adm/sa/sa files, and you create your own output; but what are you really doing? ... using my_sar -f program, after more or less effort.



Then why dont use sar -f ? piped to awk ( program lenguage ).

What i do finally is run some sar -f -$option | awk > /tmp/file_x, to format my output and then paste all file_x's > all_my_sar_data. It is too much easy.

Ok? Now i get my own output and i can use EXCEL to get grafics. See http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0x96046d96588ad4118fef0090279cd0f9,00.html

System integration? will run this in other system ? is it easy portable ?

But this was not your question. I think you must use ksysinfo struct because _KERNEL_BUILD directive needs include ../h/types.h, and that directory does not exist in ny box.

Perhaps man 2 pstat will be of your interest. See also http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0x89677e990647d4118fee0090279cd0f9,00.html


Regards.

unsupported
Ralph Grothe
Honored Contributor

Re: Reading SAR output

Hello Carlos,

I have to apologize for the late response, but I didn't find time lately to pop in to the ITRC forum.
Since I'm not too interested in MS Excel I haven't spent much time to acquire Excel-literacy.
But if I were into Excel I think I knew how to convert my raw data because I know there are some excellent (no pun intended) Win32::OLE Modules in the CPAN that could do most of the job.
Actually, for me there is no need for any spreadsheet program because I learned the fundamentals of matrix algebra and would alway prefer an individual solution where I weren't forced to waste most of the time with formatting issues and daft menu structures.
Anyway, thank you for the hint.
I hope you aren't dissapointed if I only assign you 3 points, just to show that I appreciate your effort.

Regards
Ralph
Madness, thy name is system administration