Operating System - HP-UX
1822784 Members
4049 Online
109645 Solutions
New Discussion юеВ

Using sar. How to stop it

 
SOLVED
Go to solution
Lane Frazier
Frequent Advisor

Using sar. How to stop it

Hello,

I am wanting to gather a little performance information on my HP-UX 11.0 system. Just want to get some general cpu performance info.

I want to use sar -u -f /tmp/sar.data

Here's the question...I have not seen any mention of how to use the sar command to stop the system activity reporter?

I only want to monitor for a few days and then stop it. I don't want it to run forever and waste disk space and machine resources etc.

How do I handle this?

Thanks for the help
Maybe one day I'll understand Openview?!
23 REPLIES 23
James R. Ferguson
Acclaimed Contributor

Re: Using sar. How to stop it

Lane:

Check the man pages, in particular the -s and -e options.

...JRF...
Antoanetta Naghiu
Esteemed Contributor

Re: Using sar. How to stop it

-e option is for end monitoring
James R. Ferguson
Acclaimed Contributor

Re: Using sar. How to stop it

Lane:

Check the man pages, in particular the -s and -e options.

...JRF...
Victor BERRIDGE
Honored Contributor

Re: Using sar. How to stop it

if you just want some little information..
why not put in a cron

0 * * * * sar 1 5 >/tmp/sar.log

That should do what you want no?

Best regards
Victor
Rick Garland
Honored Contributor
Solution

Re: Using sar. How to stop it

Can use the /usr/adm/sa/sa1 as a cron entry. Comment the cron entry to stop.
As an example from my cron:
0 7-18 * * 1-5 /usr/lbin/sa/sa1 1200 3

Then I have a script as follows that will convert the binary format to readable format and it is attached.

Cheryl Griffin
Honored Contributor

Re: Using sar. How to stop it

Lane,

Look at the man page for sa1 and you will see more about the ways to automate sar data.
"Downtime is a Crime."
Kofi ARTHIABAH
Honored Contributor

Re: Using sar. How to stop it

Lane:

If you set up sar as advised in the man pages, it will only maintain a maximum of 31 days worth (/var/adm/sa/sa01...31) so do not worry about collecting forever. If however within the day you want to limit the hours to collect it for, the modify the cron entry accordingly.

man sar
man sa1
nothing wrong with me that a few lines of code cannot fix!
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

Can use the /usr/adm/sa/sa1 as a cron entry. Comment the cron entry to stop.
As an example from my cron:
0 7-18 * * 1-5 /usr/lbin/sa/sa1 1200 3

Then I have a script as follows that will convert the binary format to readable format and it is attached.

Anthony deRito
Respected Contributor

Re: Using sar. How to stop it

Lane, you want to save space and still have all the sar data you need? Use the /usr/lbin/sa/sadc command instead of sar. This will create much smaller binary files. Run the command:

/usr/lbin/sa/sadc 10 300 [filename]

This will create a binary file called [filename].

Extract the data with the following command(s):

sar -u -f [filename]
or
sar -b -f [filename]
or
sar -d -f [filename]
or
Use any other sar option.

You have all the sar data you need in one compact binary file. You can put the sadc command in crontab too!

Tony
Anthony deRito
Respected Contributor

Re: Using sar. How to stop it

Lane, you want to save space and still have all the sar data you need? Use the /usr/lbin/sa/sadc command instead of sar. This will create much smaller binary files. Run the command:

/usr/lbin/sa/sadc 10 300 [filename]

This will create a binary file called [filename].

Extract the data with the following command(s):

sar -u -f [filename]
or
sar -b -f [filename]
or
sar -d -f [filename]
or
Use any other sar option.

You have all the sar data you need in one compact binary file. You can put the sadc command in crontab too!

Tony
Anthony deRito
Respected Contributor

Re: Using sar. How to stop it

Lane, you want to save space and still have all the sar data you need? Use the /usr/lbin/sa/sadc command instead of sar. This will create much smaller binary files. Run the command:

/usr/lbin/sa/sadc 10 300 [filename]

This will create a binary file called [filename].
Extract the data with the following command(s):

sar -u -f [filename]
or
sar -b -f [filename]
or
sar -d -f [filename]
or
...use any other sar option.

You have all the sar data you need in one compact binary file. You can put the sadc command in crontab too!

Tony
Anthony Goonetilleke
Esteemed Contributor

Re: Using sar. How to stop it

Here is a simple perl script to get a snapshot of CPU/DISK/MEMORY

#!/usr/local/bin/perl
$DATE=`date`;
chop($DATE);
@STATS=`/usr/bin/sar -uM 1 5`;
@STATS2=`/usr/bin/iostat 2 5`;
@STATS3=`/usr/sbin/swapinfo -mt`;
print ("START $DATE");
print "-----CPU STATS-----";
print "@STATSn";
print "-----DISK STATS-----";
print "@STATS2n";
print "-----MEMORY STATS-----";
print "@STATS3n";
print ("END $DATEnn*****");


Minimum effort maximum output!
Lane Frazier
Frequent Advisor

Re: Using sar. How to stop it

hello again,

Rick

I've put 0 7-18 * * 1-5 /usr/lbin/sa/sa1 1200 3 in my cronfile

I get the following error message back when it executes:

can't create/open data file no such file or directory

I have sa1 sa2 and sadc in the /usr/lbin/sa directory...What's the problem
Maybe one day I'll understand Openview?!
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

Do you have the directory /var/adm/sa?

This is where the sa files will go.
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

Under the /var/adm/sa directory, the data files sa$DATE will be placed. Using the sa2 command (in the script I attached) will issue the various options and convert to text output.

The 1200 tag on the end of the cron says to get the data every 20 min. Again, if you want to stop the collection, you can comment or remove from the crontab file.
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

Under the /var/adm/sa directory, the data files sa$DATE will be placed. Using the sa2 command (in the script I attached) will issue the various options and convert to text output.

The 1200 tag on the end of the cron says to get the data every 20 min. Again, if you want to stop the collection, you can comment or remove from the crontab file.

Under there I have also created the perf directory. It is just a central location to keep the text data.
Lane Frazier
Frequent Advisor

Re: Using sar. How to stop it

Rick,

There is no /var/adm/sa directory....I only have /var/adm

Do I need to create the sa subdirectory?

Thanks for your help.
Maybe one day I'll understand Openview?!
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

Yes, create the sa directory under the /var/adm.

Perms that I have for the sa directory are:
755 root sys

This will allow you to collect the data.
Lane Frazier
Frequent Advisor

Re: Using sar. How to stop it

Ok Rick,

Looks like I'm getting some data now...I have a sa17

how does one make use of your script? just copy the sa17 file to /var/adm/sa/perf

and run your script? haven't quite figured out the script you provided yet. What's with the directory creation at the beginning of the script? just a way of organizing the data by month day year?

Also does the script produce a report in a text file or does it display on the screen?

Thanks again
Maybe one day I'll understand Openview?!
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

The script I provided is converting the binary output of sa1 to text output via the sa2 command. The perf directory is just a repository location. The data is organized under the perf directory then under the year then the month. The filenames of the output will look like:

cpu.17Aug2000

This is one example. Inside this file will be the text output that you can read for the cpu stats for that day (today actually).

As a previous post stated, the binary output (example, sa17) will be overwritten on the 17th of the following month. The data collected from the script will organize the data into the appropriate month and therefore will not be overwritten. But you need to keep tabs on it to ensure that the /var filesystem does not fill up. Every so often you will want to compress and/or remove the files to keep the /var from filling up. The nightly backups ensure I am able to restore files if I need to and the file names allow me to discern which file I want to restore. If I need bufcache data for the month of Jul for example, I know where they were located and what the names of those files look like.

The output from the script will be stored into the files. It will not display on the screen.
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

The get_sars only needs to be run once per day. For me, I run through cron at 2345 hrs. The get_sars will 'mv' the data into /var/adm/sa/perf/$MONTH/. Doing the 'mv' command will overwrite a previously existing file.
Lane Frazier
Frequent Advisor

Re: Using sar. How to stop it

Rick,

I must be missing something....there are no get sars in the script you attached. I'm afraid you last reply really confused me......

right now I'm just collecting data and trying to figure out your script


Lane
Maybe one day I'll understand Openview?!
Rick Garland
Honored Contributor

Re: Using sar. How to stop it

The get_sars is the the name of the script I attached. Sorry to confuse you.

(That is what I named the script.)

It is in cron that I call this script (the get_sars script) once per day.

If I can help allieviate some of the confusion, e-mail me at rick.garland@convergentgroup.com