LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 10-25-2006, 06:27 AM   #1
danieldinu
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Rep: Reputation: 0
vmstat vs. sar


hi!
I try to write a program that monitors the performance of some UNIX servers. One of the paramaters that I intend to monitor is memory usage...When I started to dig in to this problem, I was confused. There are a couple of ways to display memory related data, but none of them display directly the free/used physical/swap memory. Anyway, I'm trying to figure out which data should I use for monitoring memory: those provided by "sar -r" (I started accounting on servers) or those of "vmstat" ? Do this data differ in any way?

Thanks in advance!
 
Old 10-25-2006, 07:01 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Sar can be used interactively to see the same data that can be seen using vmstat and iostat. The real value of sar is that it can keep logs of these data over a long period of time and then produce nice looking reports. This allows you to see how various system resources are being used over time. You can see if you have too little RAM on Tuesday afternoons, if the disk I/O is peaking when the Accounting Department closes their books at the end of the month, and other system performance metrics.

It is possible that sar already does what you intend to do with your program. That would mean that your program could simply run sar reports to achieve your goal.
 
Old 10-25-2006, 07:38 AM   #3
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
Good info from Stress Junkie ....

I just wanted to add, if you need the historical data (ie: to view the stats after they have happened) sar is the best tool I've found for that.

However if you want to see things real time 'top' works great and will show you what is currently happening on your system.

If you prefer the vmstat type of output, just redirect that output to a file for later review, in that way it can work like sar.

I used a very simple script to capture vmstat ouput and would cat the date and a line to it every few interations to break up the output and to show the time for a point of reference.

I think vmstat is like iostat in that the 1st observation is from since the system was up. So if you ran vmstat 1 1 The data would not be what your really after. You need that 2nd observation at the minimum. I would recomend
vmstat 30 10
that would give you 10 observations at 30 seconds apart. Use a 2nd script to append the date and a line to the same file for easier reading.

Hope this helps.
 
Old 10-25-2006, 08:01 AM   #4
danieldinu
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Original Poster
Rep: Reputation: 0
thanks! that answers my question, but only partially...
problem is that the output from these data look different.

output from sar -r -f file
freemem freeswap
15:50:00 12465 7536819

output from vmstat 1 2
vmstat 1 2
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr m0 m1 m3 m4 in sy cs us sy id
0 0 0 3940976 121192 7 15 2 1 1 0 1 0 0 0 0 383 2576 3694 2 1 98
0 0 0 3769192 99744 24 30 0 0 0 0 0 0 0 0 0 384 2990 3659 1 0 99

I managed to figure out the difference of swap data: for sar uses 512-bytes bloks, while vmstat uses kbytes. that makes the numbers somewhat alike.
but when it comes to freememory, things are a little bit more difficult. in order to have relevant data, one must ignore the first row of the vmstat output(which they say that is an average...). the second row of data (free field) does not fit the output of sar (freemem field). so , again, which data should I use? which are more relevant?

thanks again!
 
Old 10-25-2006, 11:29 AM   #5
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I understand your confusion. The problem is that system reporting utilities report different things. Most of the time you can get several different types of reports with a small change in a parameter. One example is free memory and pages swapped. The free utility man page says this:
Quote:
The -o switch disables the display of a "buffer adjusted" line. If the
-o option is not specified, free subtracts buffer memory from the used
memory and adds it to the free memory reported.
Other utilities have similar options. Then there is the issue of whether you are seeing empty pages on the free list, pages on the free list that can be reused by the process that just gave them up, pages on the free list that also have a copy of themselves in the swap partition, pages in the swap partition that do not have a copy of themselves anywhere in RAM.

Once you know about all of these variations in reports then you can use them to your advantage. In the end it is a good thing. It is confusing when you first start looking at these reporting utilities in depth.

The same thing applies to disk I/O reports. The numbers in a given report may be how many 512 byte or 1024 byte reads and writes are happening, or they may be the number of reads and writes on the disk that are the size of the file system's block size, which could be 4096 or higher, or they may include the number of write requests that were merged where several write requests become one I/O, or etc. etc.

The reporting utilities are difficult to compare until you learn exactly what each utility is telling you.

Last edited by stress_junkie; 10-25-2006 at 01:56 PM.
 
Old 10-25-2006, 06:46 PM   #6
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
Quote:
Originally Posted by danieldinu
thanks! that answers my question, but only partially...
problem is that the output from these data look different.

output from sar -r -f file
freemem freeswap
15:50:00 12465 7536819

output from vmstat 1 2
vmstat 1 2
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr m0 m1 m3 m4 in sy cs us sy id
0 0 0 3940976 121192 7 15 2 1 1 0 1 0 0 0 0 383 2576 3694 2 1 98
0 0 0 3769192 99744 24 30 0 0 0 0 0 0 0 0 0 384 2990 3659 1 0 99

I managed to figure out the difference of swap data: for sar uses 512-bytes bloks, while vmstat uses kbytes. that makes the numbers somewhat alike.
but when it comes to freememory, things are a little bit more difficult. in order to have relevant data, one must ignore the first row of the vmstat output(which they say that is an average...). the second row of data (free field) does not fit the output of sar (freemem field). so , again, which data should I use? which are more relevant?

thanks again!
Very good question. No easy answer.
I do not know the answer, but I'll tell you this. SAR does a very good job of collecting your systems data. I would let it do it's thing and not try to reinvent the wheel. However all data is relevent. I would only use vmstat output and top output when I'm spot checking performance or when I'm experiencing a performance issue. It works for me.
 
Old 10-26-2006, 01:29 AM   #7
danieldinu
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Original Poster
Rep: Reputation: 0
thank you, guys!
 
Old 10-27-2006, 01:50 AM   #8
danieldinu
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Just one last question....When I thought I understood how to get the amount of free physical memory, I read some man pages that confused me again...

here are some outputs from those man pages:

#man sar
-r Report unused memory pages and disk blocks:

freemem
average pages available to user processes.

freeswap
disk blocks available for page swapping.

#man pagesize
The pagesize utility prints the default size of a page of
memory in bytes, as returned by getpagesize(3C)


output from "sar -r -f file"
00:00:00 freemem freeswap
00:10:00 6576 7512510
00:20:00 6452 7512319
00:30:00 6482 7512693

# pagesize
8192

does this mean that free physical memory is:

6576 x 8192 = 53870592 bytes= 52608 kbytes = 51 Mbytes

is my assumption correct?

thank you very much, again!
 
Old 10-27-2006, 08:05 AM   #9
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
Your numbers look to be right, but I would double check using top. It is very easy to get your decimal point in the wrong place, but knowing how much memory is installed and using top you should be able to verify your numbers.

Here is the memory section of top, copied from one of my servers. This is what I'm referring to.

Mem: 7711616k av, 6537444k used, 1174172k free, 0k shrd, 271520k buff
5014532k actv, 886792k in_d, 126076k in_c

Swap: 4192924k av, 5612k used, 4187312k free 5045660k cached

You appear more worried about memory than anything else for performance. How much memory is installed in this system?
 
Old 10-27-2006, 09:29 AM   #10
danieldinu
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Original Poster
Rep: Reputation: 0
first of all, these data are taken from a Solaris 9 system, so "free" or "top" commands are not available.
secondly, I have 2GB RAM installed on this machine...from what I've read until know, I cannot yet state that having only 51MB of free memory is necessarly a bad thing...
finally, memory is not the only paramater I intend to monitor, but it's the one which gives me pain in the ...u know...

all I need to know for now is if my figures are correct FOR SOLARIS 9!

thanks!
 
Old 10-27-2006, 04:07 PM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You assumption is correct, most of your RAM is used, which is generally a good thing.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sar iostat sadf mpstat ? vmstat ? for Cent OS 4.2 rafiqul Linux - Newbie 6 07-16-2013 02:29 PM
vmstat UltraSoul Solaris / OpenSolaris 9 07-14-2006 10:11 PM
regarding vmstat output cnkhandar Linux - Newbie 1 07-07-2006 08:01 AM
Difference between Sar and Vmstat blurblur Linux - Newbie 3 05-03-2005 09:14 PM
vmstat shows swpd as 0 Skazi Linux - General 4 03-11-2005 03:39 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 09:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration